Hello,
Okay so I am having a weird problem, that really isn't a problem as I can work around it. I just think that it shouldn't be working this way as I have seen no code online written that way.
Here is what I am doing, I have a remote control system that transmits the status of nine momentary switches to a receiver that then turns on the corresponding reed relay.
I had the hardest of time getting the serial to "work", I wrote a simple program to turn on a led once com was set to "1" and state to "O", which is received over the hardware port, with AX as the qualifier.
I played with it for a while and no matter what I did I couldn't get the led to turn on. I had a usb to serial cable laying around but I didn't have a converter, so I ended up just ripping the box open and soldering on to the usb to serial chip before the TTL serial to RS-232 Serial converter. After doing that I opened up microcode studio serial terminal and checked the transmitting string, I would receive this AX1O, "AX" qualifier, "1" port one, "O" on. So the transmitter was working, but not the receiver.
I then tried sending AX1O from the terminal but that didn't work either. Finally about six hours over two days later I thought, well lets try sending this, AX,1,O wow it worked. So then I programmed the transmitter to send that like this HSEROUT ["AX",",",DEC 1,",","O"] and sure enough it worked.
My question is, Why do I have to have the commas?
Below is the code for the transmitter and receiver, respectfully:
PS If you know a better way please tell me, thanks.
Code:'Author: Albert Eardley 'Writen for 16F628A DEFINE OSC 20 CMCON = %00000111 OPTION_REG = %11000000 HIGH PORTA.2 HIGH PORTA.3 PAUSE 300 DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0 DEFINE HSER_SPBRG 255 ' 1200 Baud @ 1.75% DEFINE HSER_CLROERR 1 ' Clear overflow automatically mytimer VAR BYTE mytimer = 0 power VAR PORTA.2 switch0 VAR PORTB.0 switch1 VAR PORTA.1 switch2 VAR PORTA.5 switch3 VAR PORTB.3 switch4 VAR PORTB.4 switch5 VAR PORTB.5 switch6 VAR PORTB.6 switch7 VAR PORTB.7 switch8 VAR PORTA.0 INPUT switch0 INPUT switch1 INPUT switch2 INPUT switch3 INPUT switch4 INPUT switch5 INPUT switch6 INPUT switch7 INPUT switch8 INCLUDE "DT_INTS-14.bas" ' Base Interrupt System 'INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler TMR1_INT, _mytimercounter, PBP, yes endm INT_CREATE ; Creates the interrupt processor ENDASM T1CON = $31 ; Prescaler = 8, TMR1ON @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts MAIN: iF switch0 = 0 then WHILE switch0 = 0 mytimer = 0 HSEROUT ["AX",DEC 1,"O"] PAUSE 500 WEND HSEROUT ["AX",DEC 1,"I"] ENDIF IF switch1 = 0 THEN WHILE switch1 = 0 mytimer = 0 HSEROUT ["AX",DEC 2,"O"] PAUSE 500 WEND HSEROUT ["AX",DEC 2,"I"] ENDIF IF switch2 = 0 THEN WHILE switch2 = 0 mytimer = 0 HSEROUT ["AX",DEC 3,"O"] PAUSE 500 WEND HSEROUT ["AX",DEC 3,"I"] ENDIF IF switch3 = 0 THEN WHILE switch3 = 0 mytimer = 0 HSEROUT ["AX",DEC 4,"O"] PAUSE 500 WEND HSEROUT ["AX",DEC 4,"I"] ENDIF IF switch4 = 0 THEN WHILE switch4 = 0 mytimer = 0 HSEROUT ["AX",DEC 5,"O"] PAUSE 500 WEND HSEROUT ["AX",DEC 5,"I"] ENDIF IF switch5 = 0 THEN WHILE switch5 = 0 mytimer = 0 HSEROUT ["AX",DEC 6,"O"] PAUSE 500 WEND HSEROUT ["AX",DEC 6,"I"] ENDIF IF switch6 = 0 THEN WHILE switch6 = 0 mytimer = 0 HSEROUT ["AX",DEC 7,"O"] PAUSE 500 WEND HSEROUT ["AX",DEC 7,"I"] ENDIF IF switch7 = 0 THEN WHILE switch7 = 0 mytimer = 0 HSEROUT ["AX",DEC 8,"O"] PAUSE 500 WEND HSEROUT ["AX",DEC 8,"I"] ENDIF IF switch8 = 0 THEN WHILE switch8 = 0 mytimer = 0 HSEROUT ["AX",DEC 9,"O"] PAUSE 500 WEND HSEROUT ["AX",DEC 9,"I"] ENDIF GOTO MAIN mytimercounter: mytimer = mytimer + 1 IF mytimer >= 143 THEN LOW power ENDIF @ INT_RETURNCode:'Author: Albert Eardley 'Writen for 16F628A DEFINE OSC 20 CMCON = %00000111 OPTION_REG = %11000000 DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0 DEFINE HSER_SPBRG 255 ' 1200 Baud @ 1.75% DEFINE HSER_CLROERR 1 ' Clear overflow automatically switch0 VAR PORTB.0 switch1 VAR PORTB.3 switch2 VAR PORTB.4 switch3 VAR PORTB.5 switch4 VAR PORTB.6 switch5 VAR PORTB.7 switch6 VAR PORTA.0 switch7 VAR PORTA.1 switch8 VAR PORTA.2 com VAR BYTE state VAR BYTE MAIN: LOW switch0 LOW switch1 LOW switch2 LOW switch3 LOW switch4 LOW switch5 LOW switch6 LOW switch7 LOW switch8 MAIN1: HSERIN [WAIT("AX"), DEC com, state] SELECT CASE com CASE 1 WHILE state = "O" HIGH switch0 HSERIN 2000,MAIN,[WAIT("AX"), DEC com, state] IF com != 1 THEN MAIN WEND GOTO MAIN CASE 2 WHILE state = "O" HIGH switch1 HSERIN 2000,MAIN,[WAIT("AX"), DEC com, state] IF com != 1 THEN MAIN WEND GOTO MAIN CASE 3 WHILE state = "O" HIGH switch2 HSERIN 2000,MAIN,[WAIT("AX"), DEC com, state] IF com != 1 THEN MAIN WEND GOTO MAIN CASE 4 WHILE state = "O" HIGH switch3 HSERIN 2000,MAIN,[WAIT("AX"), DEC com, state] IF com != 1 THEN MAIN WEND GOTO MAIN CASE 5 WHILE state = "O" HIGH switch4 HSERIN 2000,MAIN,[WAIT("AX"), DEC com, state] IF com != 1 THEN MAIN WEND GOTO MAIN CASE 6 WHILE state = "O" HIGH switch5 HSERIN 2000,MAIN,[WAIT("AX"), DEC com, state] IF com != 1 THEN MAIN WEND GOTO MAIN CASE 7 WHILE state = "O" HIGH switch6 HSERIN 2000,MAIN,[WAIT("AX"), DEC com, state] IF com != 1 THEN MAIN WEND GOTO MAIN CASE 8 WHILE state = "O" HIGH switch7 HSERIN 2000,MAIN,[WAIT("AX"), DEC com, state] IF com != 1 THEN MAIN WEND GOTO MAIN CASE 9 WHILE state = "O" HIGH switch8 HSERIN 2000,MAIN,[WAIT("AX"), DEC com, state] IF com != 1 THEN MAIN WEND GOTO MAIN CASE ELSE GOTO MAIN END SELECT


. So then I programmed the transmitter to send that like this HSEROUT ["AX",",",DEC 1,",","O"] and sure enough it worked.


Bookmarks