I create a buffer for the transmission. For example, I'm using a Nextion where if I wanted to display RPM, I name the Nextion Number object "rpm". To send it, ASCii characters "rpm.val=1234" then $FF, $FF, $FF. I create a NexBuf[16] VAR BYTE to hold each character byte.
Here is my Send_RPM subroutine:
I'm using the UART TX Interrupt to keep feeding NexBuf through the pipeline (not LCDOOUT). But I hope this at least gives you some ideas.Code:Send_RPM: ;Send Current RPM Value to Nextion tRPM = RPM ;Create a Temporary Variable We Can Modify ARRAYWRITE NexBuf,["rpm.val="] ;Start Nextion Command Sequence, Occupies NexBuf[0] >> [7] IF tRPM > 1000 THEN ;If RPM is 4 Digits b0 = tRPM / 1000 ;Get the Xxxx Value NexBuf[8] = b0 + $30 ;Convert it to ASCii tRPM = tRPM - (b0 * 1000) ;Subtract the Xxxx Value from tRPM IF tRPM < 100 THEN ;2nd Digit = 0 NexBuf[9] = $30 ;If New tRPM < 100, Add Zero Fill (ASCii) IF tRPM < 10 THEN ;3rd Digit = 0 NexBuf[10] = $30 ;If tRPM < 10, Add Zero Fill (ASCii) ENDIF ;IF tRPM < 10 ENDIF ;IF tRPM < 100 ELSE ;tRPM < 1000 NexBuf[8] = $30 ;If tRPM < 1000, Xxxx = Zero (ASCii) ENDIF ;IF tRPM > 1000 IF tRPM > 100 THEN ;If RPM is 3 Digits b0 = tRPM / 100 ;Get the xXxx Value NexBuf[9] = b0 + $30 ;Convert it to ASCii tRPM = tRPM - (b0 * 100) ;Subtract the xXxx Value from tRPM IF tRPM < 10 THEN ;3rd Digit = 0 NexBuf[10] = $30 ;If tRPM < 10, Add Zero Fill (ASCii) ENDIF ;IF tRPM < 10 ELSE ;tRPM < 100 NexBuf[9] = $30 ;If tRPM < 100, it's Zero (ASCii) ENDIF ;IF tRPM > 100 IF tRPM > 10 THEN ;If RPM is 2 Digits b0 = tRPM / 10 ;Get the xxXx Value NexBuf[10] = b0 + $30 ;Convert it to ASCii tRPM = tRPM - (b0 * 10) ;Subtract the xxXx Value from tRPM ELSE ;tRPM < 10 NexBuf[10] = $30 ;If tRPM < 10, it's Zero (ASCii) ENDIF ;IF tRPM > 10 NexBuf[11] = tRPM + $30 ;Convert xxxX Value to ASCii & Add to Buffer FOR b0 = 12 TO 14 ;Generate "End of Message" Sequence: $FF, $FF, $FF NexBuf[b0] = $FF ;Load it to Buffer NEXT b0 ;FOR b0 = 12 TO 14 NexBuf[15] = 0 ;Tells Us To Turn UART TX INT Off RotX = 0 ;NexFlags.RotX -- Clear RotX Flag GOTO Start_TX ;No RETURN Needed, Using GOTO Command




Bookmarks