''-------MAVLINK_TEST2------- '' ''[FE][ ][ ][80][80][??????????? CON _CLKMODE = xtal1 + pll16x _XINFREQ = 5_000_000 VAR byte param1 [150] 'array van 100 bytes ********************* long cog 'Cog flag/id OBJ PUB Start bytefill(@param1,0,150) cog := cognew(@entry,@param1) + 1 DAT org entry MOV tmp1,par 'geg van param1 MOV t2,tmp1 'adress of param1 save to t2 ANDN dira, Rxmask 'Mask=1, with andn dira=>0 =>input @57600 OR dira,TxMask 'Mask=1, with OR dira=>1 => output @57600 BEGIN MOV Byt32Cnt,BytGetal32 MOV t4,#%1 '=for check if startbyte ok MOV t3,t2 receive TEST Rxmask,ina WZ 'wait for start bit on rx pin IF_NZ JMP #receive MOV rxbits,#9 'ready to receive byte 9 == 8bit + stopbit ????? MOV rxcnt,bitticks SHR rxcnt,#1 ADD rxcnt,cnt :bit ADD rxcnt,bitticks 'ready next bit period :wait MOV t1,rxcnt 'check if bit receive period done SUB t1,cnt CMPS t1,#0 WC IF_NC JMP #:wait TEST Rxmask,ina WC 'receive bit on rx pin RCR rxdata,#1 'rcr DJNZ rxbits,#:bit SHR rxdata,#32-9 'justify and trim received byte AND rxdata,#$FF cmp t4,#%0 wz 'compare if startbyte ok if_z jmp #:schrijf '**************START****************** cmp rxdata ,#$FE wz 'wait for 0xFE if_nz jmp #receive 'if startbyte nok jump recieve mov t4,#%0 'startbyte = ok '************************************* :schrijf ADD t3,#1 'write buffer WRBYTE rxdata,t3 DJNZ Byt32Cnt , #receive '=====lees buffer=============================================================================================== LeesBuffer MOV t5,t2 MOV Byt32Cnt,BytGetal32 NXTByt ADD t5,#1 RDBYTE txdt,t5 'read the byte to transmit or txdt,#%1_0000_0000 ' 0000_0000_0000_0000_0001_XXXX_XXXX =>stopbit SHL txdt,#2 ' 0000_0000_0000_0000_01XX_XXXX_XX00 2 or txdt,#1 ' 0000_0000_0000_0000_01XX_XXXX_XX01 =>Startbit;idle MOV txbits,#11 ' 11 MOV txcnt,cnt :bit1 SHR txdt,#1 WC MUXC outa,Txmask ADD txcnt,bitticks 'ready next cnt :wait1 MOV t6,txcnt 'check if bit transmit period done SUB t6,cnt CMPS t6,#0 WC IF_NC JMP #:wait1 DJNZ txbits,#:bit1 DJNZ Byt32Cnt,#NXTByt JMP #BEGIN 'konstante ------------------------------------------------------------------------------------------ tmp1 long 0 'par t1 long 0 t2 long 0 'adress of param1 t3 long 0 'array pointer t4 long 0 'startbyte ok t5 long 0 t6 long 0 rxtxmode long 0 Rxmask long |<1 'data in pin txmask long |<2 'data out pin BytGetal32 long 32 '=32 bytes bitticks long 1440 '==>57600 baud '~=4800baud =>~ 0.22mS/bit => 80000*0.22=17600 '~=9600baud =>~ 0.11mS/bit => 80000*0.11=8800 '~=19200baud =>~ 0.052mS/bit => 80000*0.052=4160 '~=38400baud =>~ 0.027mS/bit => 80000*0.027=2160 '~=57600baud =>~ 0.018mS/bit => 80000*0.018=1440 rxdata res 1 rxbits res 1 rxcnt res 1 byt32Cnt res 1 txdt res 1 txbits res 1 txcnt res 1 '========================================================================================================= fit 496