Full Code:
Code:
ASM
__CONFIG _CONFIG1H, _OSC_HSPLL_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
ENDASM
DEFINE OSC 48 ; uses 12Mhz xtal
ADCON1 = $0F
clear
DEFINE LCD_DREG PORTB ' LCD Data port
DEFINE LCD_DBIT 0 ' starting Data bit (0 or 4)
DEFINE LCD_EREG PORTB ' LCD Enable port
DEFINE LCD_EBIT 5 ' Enable bit (on EasyPIC 5 LCD)
DEFINE LCD_RSREG PORTB ' LCD Register Select port
DEFINE LCD_RSBIT 4 ' Register Select bit (on EasyPIC 5 LCD)
DEFINE LCD_BITS 4 ' LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 4 ' number of lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Command delay time in us
DEFINE LCD_DATAUS 50 ' Data delay time in us
;----[Port settings]----------------------------------------------------
TRISA = %11001111
TRISB = %00000000
TRISD = %00001111
CMCON = 7 ' disable Comparators
;----[USART defines]--------------------------------------------------------
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_SPBRG 25 ' 115200 Baud @ 48MHz, 0.16%
SPBRGH = 0
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
ColumnWidth CON 10
TempWD VAR WORD
RCIF VAR PIR1.5 ' USART receive flag
GIE VAR INTCON.7
tr var byte
normtemp VAR WORD[4] ' used to store the desired temperature setting
normtemp1 VAR normtemp[0]
normtemp2 VAR normtemp[1]
normtemp3 VAR normtemp[2]
normtemp4 VAR normtemp[3]
nTest var byte
temphold var byte
temp var byte
TimeoutCount var byte
;---------------------------------------------------------------------
;set test values
normtemp[0]=240
normtemp[1]=250
normtemp[2]=260
normtemp[3]=270
;______________________________________________________________
gosub FlushBuffer
main:
FOR TempWD = 0 TO 1000
IF RCIF=1 THEN GOsub Term_RX
PAUSE 1
NEXT TempWD
pause 200
goto main
Term_RX:
HSERIN[nTest]
SELECT CASE nTest
CASE "S"
TempWD = 0
HSERIN 1000,RX_Bombed,[DEC3 TempWD]
normtemp[0] = TempWD
gosub send
Goto Term_Rx
RX_Bombed:
TimeoutCount = TimeOutCount + 1
lcdOUT $FE,1,"all we got was", dec TempWD,", ", DEC TimeOutCount
end select
Goto Term_Rx
Send:
HSEROUT [DEC normtemp[0],10]
setpoints(0)=normtemp[0]
LCDOut $FE,$D4,#setpoints(0)dig 2,#setpoints(0)dig 1,#setpoints(0)dig 0
RETURN
FlushBuffer:
While PIR1.5
HSERIN [TempWd]
WEND
TempWd=0
LCDOUT $FE,1,"Buffer flushed"
RETURN
I tried this at 2400 baud (having use PIC multicalc to get the Uart setting) and it gave one error and then echoed all the subsequent entry's correctly. I then changed it back to 115200 and it works a treat
- even with my friends application.
Henrick thanks for taking the time out to assist me with this, and for explaining the serial function in laymens terms, I have learnt a lot from your posts.
Now just got to amend the code so that it does the same for all the other variables 
I think Charles was going to have his application send one long string of all the variables, maybe I should ask him if he can make it user selected so it updates just the one ?
Bookmarks