[color=Green]'*******************************************************
'* 18M2 receives 4 bytes of serial data from terminal "A".
'* Converts Ascii data to decimal & writes to RAM.
'* Reads data from RAM then sequences thru data
'* using variable b1.
'* NEED TO INTEGRATE WITH AXE133Y CODE SO CAN ELIMINATE
'* THE INTERMEDIATE TERMINAL "B". SEROUT TO THE OLED
'* ARE ONLY USED FOR TESTING CODE WITH PE6 SIMULATE.
'* WILL BE REMOVED IN FINAL CODE>
'*******************************************************[/color]
[color=Navy]#picaxe [/color][color=Black]18M2 [/color][color=Green]'In AXE133Y OLED display.[/color]
[color=Blue]symbol RCV [/color][color=DarkCyan]= [/color][color=Blue]C.5
symbol oled [/color][color=DarkCyan]= [/color][color=Blue]C.3
symbol RLED [/color][color=DarkCyan]= [/color][color=Blue]C.2
symbol [/color][color=Purple]RAM_addr [/color][color=DarkCyan]= [/color][color=Purple]b0[/color]
[color=Blue]symbol [/color][color=Purple]rcv1 [/color][color=DarkCyan]= [/color][color=Purple]b6[/color]
[color=Blue]symbol [/color][color=Purple]rcv2 [/color][color=DarkCyan]= [/color][color=Purple]b7[/color]
[color=Blue]symbol [/color][color=Purple]rcv3 [/color][color=DarkCyan]= [/color][color=Purple]b8[/color]
[color=Blue]symbol [/color][color=Purple]rcv4 [/color][color=DarkCyan]= [/color][color=Purple]b9[/color]
[color=Blue]symbol [/color][color=Purple]temp_dig[/color][color=DarkCyan]= [/color][color=Purple]b10[/color]
[color=Blue]symbol [/color][color=Purple]dig1 [/color][color=DarkCyan]= [/color][color=Purple]b16[/color]
[color=Blue]symbol [/color][color=Purple]dig2 [/color][color=DarkCyan]= [/color][color=Purple]b17[/color]
[color=Blue]symbol [/color][color=Purple]dig3 [/color][color=DarkCyan]= [/color][color=Purple]b18[/color]
[color=Green]' Typical lights ON message: 120,22,33,44 .
' Typical lights OFF message. 56,22,33,44 .[/color]
[color=Purple]RAM_addr [/color][color=DarkCyan]= [/color][color=Navy]30 [/color][color=Green]'Starting address for RAM data.[/color]
[color=Black]init: [/color][color=Green]'Load Template for fixed OLED data into RAM.
[/color][color=Blue]poke [/color][color=Navy]30[/color][color=Black],[/color][color=Navy]254[/color][color=Black],[/color][color=Navy]128[/color][color=Black],[/color][color=Navy]76[/color][color=Black],[/color][color=Navy]49[/color][color=Black],[/color][color=Navy]58 [/color][color=Green]'go to pos 128,L,I,:
[/color][color=Blue]poke [/color][color=Navy]38[/color][color=Black],[/color][color=Navy]254[/color][color=Black],[/color][color=Navy]138[/color][color=Black],[/color][color=Navy]84[/color][color=Black],[/color][color=Navy]49[/color][color=Black],[/color][color=Navy]58 [/color][color=Green]'go to pos 138,T,1,:
[/color][color=Blue]poke [/color][color=Navy]46[/color][color=Black],[/color][color=Navy]254[/color][color=Black],[/color][color=Navy]192[/color][color=Black],[/color][color=Navy]84[/color][color=Black],[/color][color=Navy]50[/color][color=Black],[/color][color=Navy]58 [/color][color=Green]'go to pos 192,T,2,:
[/color][color=Blue]poke [/color][color=Navy]54[/color][color=Black],[/color][color=Navy]254[/color][color=Black],[/color][color=Navy]202[/color][color=Black],[/color][color=Navy]84[/color][color=Black],[/color][color=Navy]51[/color][color=Black],[/color][color=Navy]58 [/color][color=Green]'go to pos 202,T,3,:
[/color]
[color=Black]Main:
rcv_data: [/color][color=Green]'Receive serial data from terminal "A".
[/color][color=Blue]serin rcv[/color][color=Black],[/color][color=Blue]n2400[/color][color=Black],[/color][color=Purple]rcv1[/color][color=Black],[/color][color=Purple]rcv2[/color][color=Black],[/color][color=Purple]rcv3[/color][color=Black],[/color][color=Purple]rcv4
[/color][color=Blue]call [/color][color=Black]check_1st [/color][color=Green]'Check if terminal "A" lights are ON/OFF.
'** Analyze receive data & convert binary to Ascii. [/color]
[color=Black]convert:
[/color][color=Blue]call [/color][color=Black]check_1st
[/color][color=Blue]poke [/color][color=Navy]35[/color][color=Black],[/color][color=Purple]dig1[/color][color=Black],[/color][color=Purple]dig2[/color][color=Black],[/color][color=Purple]dig3 [/color][color=Green]'Writes to RAM address 35,36,37.
[/color][color=Blue]BinToAscii [/color][color=Purple]rcv2[/color][color=Black],[/color][color=Purple]dig1[/color][color=Black],[/color][color=Purple]dig2[/color][color=Black],[/color][color=Purple]dig3
[/color][color=Blue]call [/color][color=Black]check
[/color][color=Blue]poke [/color][color=Navy]43[/color][color=Black],[/color][color=Purple]dig1[/color][color=Black],[/color][color=Purple]dig2[/color][color=Black],[/color][color=Purple]dig3 [/color][color=Green]'Writes to RAM address 43,44,45.
[/color][color=Blue]BinToAscii [/color][color=Purple]rcv3[/color][color=Black],[/color][color=Purple]dig1[/color][color=Black],[/color][color=Purple]dig2[/color][color=Black],[/color][color=Purple]dig3
[/color][color=Blue]call [/color][color=Black]check
[/color][color=Blue]poke [/color][color=Navy]51[/color][color=Black],[/color][color=Purple]dig1[/color][color=Black],[/color][color=Purple]dig2[/color][color=Black],[/color][color=Purple]dig3 [/color][color=Green]'Writes to RAM address 51,52,53.
[/color][color=Blue]BinToAscii [/color][color=Purple]rcv4[/color][color=Black],[/color][color=Purple]dig1[/color][color=Black],[/color][color=Purple]dig2[/color][color=Black],[/color][color=Purple]dig3
[/color][color=Blue]call [/color][color=Black]check
[/color][color=Blue]poke [/color][color=Navy]59[/color][color=Black],[/color][color=Purple]dig1[/color][color=Black],[/color][color=Purple]dig2[/color][color=Black],[/color][color=Purple]dig3 [/color][color=Green]'Writes to RAM address 59,60,61
[/color][color=Blue]call [/color][color=Black]see_data
[/color][color=Blue]high RLED[/color][color=Black]:[/color][color=Blue]pause [/color][color=Navy]500[/color][color=Black]:[/color][color=Blue]low RLED [/color][color=Green]'Terminal "heartbeat".
[/color][color=Blue]goto [/color][color=Black]main[/color]
[color=Green]'** Analyze 1st character received to see
'** if terminal "A" ilghts are ON/OFF. [/color]
[color=Black]check_1st:
[/color][color=Blue]if [/color][color=Purple]rcv1 [/color][color=DarkCyan]=>[/color][color=Navy]100 [/color][color=Blue]then let [/color][color=Purple]dig1[/color][color=DarkCyan]=[/color][color=Navy]32[/color][color=Black]:[/color][color=Purple]dig2[/color][color=DarkCyan]=[/color][color=Navy]79[/color][color=Black]:[/color][color=Purple]dig3[/color][color=DarkCyan]=[/color][color=Navy]78 [/color][color=Green]'space, O,N.[/color]
[color=Blue]else let [/color][color=Purple]dig1[/color][color=DarkCyan]=[/color][color=Navy]79[/color][color=Black]:[/color][color=Purple]dig2[/color][color=DarkCyan]=[/color][color=Black]70dig3[/color][color=DarkCyan]=[/color][color=Navy]70[/color][color=Black]:[/color][color=Blue]endif [/color][color=Green]'O,F,F.
[/color][color=Blue]return[/color]
[color=Green]'** Analyze 2nd,3rd,4th received characters.
'** Replace leading zero's with spaces.[/color]
[color=Black]check:
[/color][color=Blue]if [/color][color=Purple]dig1 [/color][color=DarkCyan]=[/color][color=Navy]48 [/color][color=DarkCyan]and [/color][color=Purple]dig2 [/color][color=DarkCyan]=[/color][color=Navy]48 [/color][color=Blue]then [/color][color=Black]char_1
[/color][color=Blue]if [/color][color=Purple]dig1[/color][color=DarkCyan]=[/color][color=Navy]48 [/color][color=Blue]then [/color][color=Black]char_2
[/color][color=Blue]goto [/color][color=Black]char_3
char_1:
[/color][color=Purple]dig1 [/color][color=DarkCyan]= [/color][color=Navy]32[/color][color=Black]:[/color][color=Purple]dig2 [/color][color=DarkCyan]= [/color][color=Navy]32 [/color][color=Black]:[/color][color=Blue]pause [/color][color=Navy]10
[/color][color=Purple]pinsB[/color][color=DarkCyan]=[/color][color=Purple]b1 [/color][color=Green]'Watch data on pinsB.
[/color][color=Blue]return
goto [/color][color=Black]main
char_2:
[/color][color=Purple]dig1 [/color][color=DarkCyan]= [/color][color=Navy]32[/color][color=Black]:[/color][color=Blue]pause [/color][color=Navy]10
[/color][color=Purple]pinsB[/color][color=DarkCyan]=[/color][color=Purple]b1 [/color][color=Green]'Watch data on pinsB.
[/color][color=Blue]return
goto [/color][color=Black]main
char_3:
[/color][color=Purple]pinsB[/color][color=DarkCyan]=[/color][color=Purple]b1 [/color][color=Green]'Watch data on pinsB.
[/color][color=Blue]return
[/color]
[color=Black]see_data:
[/color][color=Blue]serout oled[/color][color=Black],[/color][color=Blue]n2400[/color][color=Black],[/color][color=Blue]([/color][color=Navy]254[/color][color=Black],[/color][color=Navy]1[/color][color=Blue])
[/color][color=Purple]b0[/color][color=DarkCyan]=[/color][color=Navy]30
[/color][color=Blue]for [/color][color=Purple]b21[/color][color=DarkCyan]=[/color][color=Navy]1 [/color][color=Blue]to [/color][color=Navy]32
[/color][color=Blue]peek [/color][color=Purple]b0[/color][color=Black],[/color][color=Purple]b19[/color][color=Green]',254,128,76,49,58
[/color][color=Blue]serout oled[/color][color=Black],[/color][color=Blue]n2400[/color][color=Black],[/color][color=Blue]([/color][color=Purple]b19[/color][color=Blue])
inc [/color][color=Purple]b0
[/color][color=Blue]next [/color][color=Purple]b21
[/color][color=Blue]return
[/color]