Curly one

i2c4me

New Member
I have started to write a program to control a radio transceiver (FT817) with an 18X and having a keypad and LCD. So far I have the Lcd display working and the keypad routine gets key presses, converts them to ascii and sends them to the LCD. So far so good. Then I turn off the device, come back to it later and the program sets up the LCD but nothing happens with regard to key presses, it's as if there is a stop command just before the program goes off to the getkey routine. Debug doesn't work either.

Code:
	  SYMBOL  RS        = 2         ; 0 = Command   1 = Data
        SYMBOL  E         = 3         ; 0 = Idle      1 = Active
        SYMBOL  DB4       = 4         ; LCD Data Line 4
        SYMBOL  DB5       = 5         ; LCD Data Line 5
        SYMBOL  DB6       = 6         ; LCD Data Line 6
        SYMBOL  DB7       = 7         ; LCD Data Line 7

        SYMBOL  RSCMDmask = %00000000 ; Select Command register
        SYMBOL  RSDATmask = %00000100 ; Select Data register

	  SYMBOL  counter	  = b3
	  SYMBOL  Val	  = b6
	  SYMBOL  Col       = b7
        SYMBOL  Row       = b8
        SYMBOL  Polin     = b9
	  SYMBOL  Pol	  = b10
	  SYMBOL  get       = b11
        SYMBOL  bite      = b12
        SYMBOL  rsbit     = b13

	EEPROM $50,(0,0,0,0,0,1,4,7,14,2,5,8,0,3,6,9,15,10,11,12,13)
		' lookup table for keypad
	EEPROM $70,("VFO TOGL")
	EEPROM $80,("FREQ.MHz") ' store the text in the EEPROM memory
	EEPROM $90,("MODE 0-7")


'Start -----------------------------------------------------------
    PowerOnReset:
	
        GOSUB InitialiseLcd

    DisplayFirstLine:

        FOR get = $80 TO $87		'display the first message (FREQ.MHz)
          READ get,bite
          GOSUB SendDataByte
        NEXT

    MoveCursorToStartOfSecondLine:

        bite = $C0
        GOSUB SendCmdByte

    GetEightKeyPresses:
		for counter=1 to 8
		gosub getkey
		bite = Val + 48
		Gosub SendDataByte
		next counter
	goto DisplayFirstLine

  stop
        FOR get = 16 TO 22
          READ get,bite
          GOSUB SendDataByte
        NEXT

        END
'Subs ---------------------------------------------------------------
    InitialiseLcd:

        FOR get = 0 TO 5
          READ get,bite
          GOSUB SendInitCmdByte
        NEXT

        ' Nibble commands - To initialise 4-bit mode

        EEPROM 0,( $33 )    ; %0011---- %0011----   8-bit / 8-bit
        EEPROM 1,( $32 )    ; %0011---- %0010----   8-bit / 4-bit

        ' Byte commands - To configure the LCD

        EEPROM 2,( $28 )    ; %00101000 %001LNF00   Display Format
        EEPROM 3,( $0F )    ; %00001111 %00001DCB   Display On,cursor on,flash on
        EEPROM 4,( $06 )    ; %00000110 %000001IS   Cursor Move

                            ; L : 0 = 4-bit Mode    1 = 8-bit Mode
                            ; N : 0 = 1 Line        1 = 2 Lines
                            ; F : 0 = 5x7 Pixels    1 = N/A
                            ; D : 0 = Display Off   1 = Display On
                            ; C : 0 = Cursor Off    1 = Cursor On
                            ; B : 0 = Cursor Steady 1 = Cursor Flash
                            ; I : 0 = Dec Cursor    1 = Inc Cursor
                            ; S : 0 = Cursor Move   1 = Display Shift

        EEPROM 5,( $01 )    ; Clear Screen

        RETURN

    SendInitCmdByte:

        PAUSE 15                        ; Delay 15mS

    SendCmdByte:

        rsbit = RSCMDmask               ; Send to Command register

    SendDataByte:

        pins = bite & %11110000 | rsbit ; Put MSB out first
        PULSOUT E,1                     ; Give a 10uS pulse on E
        pins = bite * %00010000 | rsbit ; Put LSB out second
        PULSOUT E,1                     ; Give a 10uS pulse on E

        rsbit = RSDATmask               ; Send to Data register next

        RETURN
'-----------------------------------------------------------------
getkey:
	let pins=0					'clear out pins
	Pol=16
g1:	pins=Pol
	lookdown Pol,(0,16,32,64,128),Col	'compare Pol & values ->Col
	Polin=pins					'input the pins value
	lookdown Polin,(0,128,1,2,4),Row	'compare with values -> Row
	if Row <>0 then exitgk			
	if Pol=128 then getkey			' if 0 no key pressed
	Pol=Pol*2
	goto g1

exitgk:	
	Col=Col*4				' shift 2 places
	Col=Col+Row+$50			' then add to 'lower half' plus start of lookup table
	debug
	read Col,Val			' read key from table
e1:	Polin=pins
	if Polin <>0 then e1		' wait til key released
	return
Like I said, download the program and it works, powercycle the picaxe and it locks up after the first line is sent to the LCD. Any thoughts?
 
Last edited:

papaof2

Senior Member
Do you have the 10K/22K download resistors on the PICAXE board?

Are you disconnecting the download cable after programming the PICAXE?

If the download pin is not pulled low by the resistor, then the PICAXE may see the serial in as a high and think it should go into download mode.

John
 

Andrew Cowan

Senior Member
The code seems OK - what power supply are you using?

Put your code /code in square brackets [like this] to make the code more readable.

A
 

hippy

Ex-Staff (retired)
Connect up the download cable, liberally sprinkle SERTXD's in important parts of the program and see where the program is going when you power off, and come back later.

For this type of debugging I tend to use SERTXD("{1}") incrementing for each SERTXD so you get a long stream of digits, and it's easy to find the relevant ones if it goes into a tight loop etc. Once you have some idea of where it's going ( or not ) fine tune the SERTXD to prove / disprove what might be happening.
 

i2c4me

New Member
Thanks for your responses guys. To answer your queries, I always put the download circuit on the boards, the power supply is 12V dropped down to 5V by a 7805 Reg, and I'll definitely try the Sertxd idea as soon as I can.
Thanks again,
Paul
 

i2c4me

New Member
Hooray, Papaof2 had it pegged! I still had the download cable plugged into the 'box'. Removed it and all is as it should be! The computers serial port must have been raising the serin line.....

Many thankyous,:D
 
Top