Code:
;----[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
alarmhigh VAR WORD[4] ' used to store the desired high temp alarm values
alarmhigh1 VAR alarmhigh[0]
alarmhigh2 VAR alarmhigh[1]
alarmhigh3 VAR alarmhigh[2]
alarmhigh4 VAR alarmhigh[3]
alarmlow VAR WORD[4] ' used to store the desired low temp alarm values
alarmlow1 VAR alarmlow[0]
alarmlow2 VAR alarmlow[1]
alarmlow3 VAR alarmlow[2]
alarmlow4 VAR alarmlow[3]
lightsetHR VAR WORD[4] ' user to set light on hour
lightsetHR1 VAR lightsetHR[0]
lightsetHR2 VAR lightsetHR[1]
lightsetHR3 VAR lightsetHR[2]
lightsetHR4 VAR lightsetHR[3]
lightsetMN VAR WORD[4]
lightsetMN1 VAR lightsetMN[0]
lightsetMN2 VAR lightsetMN[1]
lightsetMN3 VAR lightsetMN[2]
lightsetMN4 VAR lightsetMN[3]
lightoffHR VAR WORD[4]
lightoffHR1 VAR lightoffHR[0]
lightoffHR2 VAR lightoffHR[1]
lightoffHR3 VAR lightoffHR[2]
lightoffHR4 VAR lightoffHR[3]
lightoffMN VAR WORD[4]
lightoffMN1 VAR lightoffMN[0]
lightoffMN2 VAR lightoffMN[1]
lightoffMN3 VAR lightoffMN[2]
lightoffMN4 VAR lightoffMN[3]
StartHour VAR WORD[4]
StartHour1 VAR StartHour[0]
StartHour2 VAR StartHour[1]
StartHour3 VAR StartHour[2]
StartHour4 VAR StartHour[3]
StartMin VAR WORD[4]
StartMin1 VAR StartMin[0]
StartMin2 VAR StartMin[1]
StartMin3 VAR StartMin[2]
StartMin4 VAR StartMin[3]
StopHour VAR WORD[4]
StopHour1 VAR StopHour[0]
StopHour2 VAR StopHour[1]
StopHour3 VAR StopHour[2]
StopHour4 VAR StopHour[3]
StopMin VAR WORD[4]
StopMin1 VAR StopMin[0]
StopMin2 VAR StopMin[1]
StopMin3 VAR StopMin[2]
StopMin4 VAR StopMin[3]
Droptemp VAR WORD[4]
droptemp1 var Droptemp[0]
droptemp2 var Droptemp[1]
droptemp3 var Droptemp[2]
droptemp4 var Droptemp[3]
Temperatures VAR WORD[4]
Temp1 VAR Temperatures[0]
Temp2 VAR Temperatures[1]
Temp3 VAR Temperatures[2]
Temp4 VAR Temperatures[3]
SetPoints VAR WORD[4] ' used to store the desired temperature setting
SetPoint1 VAR SetPoints[0]
SetPoint2 VAR SetPoints[1]
SetPoint3 VAR SetPoints[2]
SetPoint4 VAR SetPoints[3]
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]
FlashStar VAR BIT
nTest var byte
;---------------------------------------------------------------------
;set test values
Temperatures[0]=230
Temperatures[1]=240
Temperatures[2]=250
Temperatures[3]=260
normtemp[0]=240
normtemp[1]=250
normtemp[2]=260
normtemp[3]=270
alarmlow[0]=180
alarmlow[1]=180
alarmlow[2]=180
alarmlow[3]=180
alarmhigh[0]=360
alarmhigh[1]=360
alarmhigh[2]=360
alarmhigh[3]=360
StartHour1=00
StartHour2=00
StartHour3=00
StartHour4=00
StartMin1=00
StartMin2=00
StartMin3=00
StartMin4=00
StopHour1=00
StopHour2=00
StopHour3=00
StopHour4=00
StopMin1=00
StopMin2=00
StopMin3=00
StopMin4=00
Droptemp[0]=180
Droptemp[1]=180
Droptemp[2]=180
Droptemp[3]=180
lightsetHR1=00
lightsetHR2=00
lightsetMN1=00
lightsetMN2=00
lightoffHR1=00
lightoffHR2=00
lightoffMN1=00
lightoffMN2=00
;______________________________________________________________
main:
If PIR1.5 = 1 Then 'check to see if there is data in the serial buffer
HSERIN[nTest]
if nTest = "S" then
gosub Term_RX
endif
endif
for tempwd = 0 to 3
setpoints(tempwd)=normtemp(tempwd)
next
LCDOut $FE,$D4+8,#setpoints(0)dig 2,#setpoints(0)dig 1,$FE,$D4+11,#setpoints(1)dig 2,#setpoints(1)dig 1 ' show current set temperatures
LCDOut $FE,$D4+14,#setpoints(2)dig 2,#setpoints(2)dig 1,$FE,$D4+17,#setpoints(3)dig 2,#setpoints(3)dig 1
LCDOUT $FE,$80 + 18,("*"&FlashStar*$FF)|(" "&~(FlashStar*$FF)) ; flash a star to show sample time, but used to indicate Alarm settings monitored
FlashStar = !FlashStar
Hserout [DEC3 Temperatures[0]]
Hserout [DEC3 Temperatures[1]]
Hserout [DEC3 Temperatures[2]]
Hserout [DEC3 Temperatures[3]]
HSEROUT [dec3 normtemp[0]]
HSEROUT [dec3 normtemp[1]]
HSEROUT [dec3 normtemp[2]]
HSEROUT [dec3 normtemp[3]]
Hserout [dec3 alarmlow[0]]
Hserout [dec3 alarmlow[1]]
Hserout [dec alarmlow[2]]
Hserout [dec alarmlow[3]]
Hserout [dec3 alarmhigh[0]]
Hserout [dec3 alarmhigh[1]]
Hserout [dec3 alarmhigh[2]]
Hserout [dec3 alarmhigh[3]]
hserout [#StartHour[0] DIG 1,#StartHour[0] DIG 0,#StartMin[0] DIG 1,#StartMin[0] DIG 0]
hserout [#StartHour[1] DIG 1,#StartHour[1] DIG 0,#StartMin[1] DIG 1,#StartMin[1] DIG 0]
hserout [#StartHour[2] DIG 1,#StartHour[2] DIG 0,#StartMin[2] DIG 1,#StartMin[2] DIG 0]
hserout [#StartHour[3] DIG 1,#StartHour[3] DIG 0,#StartMin[3] DIG 1,#StartMin[3] DIG 0]
hserout [#StopHour[0] DIG 1,#StopHour[0] DIG 0,#StopMin[0] DIG 1,#StopMin[0] DIG 0]
hserout [#StopHour[1] DIG 1,#StopHour[1] DIG 0,#StopMin[1] DIG 1,#StopMin[1] DIG 0]
hserout [#StopHour[2] DIG 1,#StopHour[2] DIG 0,#StopMin[2] DIG 1,#StopMin[2] DIG 0]
hserout [#StopHour[3] DIG 1,#StopHour[3] DIG 0,#StopMin[3] DIG 1,#StopMin[3] DIG 0]
Hserout [dec3 Droptemp[0]]
Hserout [dec3 Droptemp[1]]
Hserout [dec3 Droptemp[2]]
Hserout [dec3 Droptemp[3]]
hserout [#lightsetHR[0] DIG 1,#lightsetHR[0] DIG 0,#lightsetMN[0] DIG 1,#lightsetMN[0] DIG 0]
hserout [#lightsetHR[1] DIG 1,#lightsetHR[1] DIG 0,#lightsetMN[1] DIG 1,#lightsetMN[1] DIG 0]
hserout [#lightoffHR[0] DIG 1,#lightoffHR[0] DIG 0,#lightoffMN[0] DIG 1,#lightOFFMN[0] DIG 0]
hserout [#lightoffHR[1] DIG 1,#lightoffHR[1] DIG 0,#lightoffMN[1] DIG 1,#lightOFFMN[1] DIG 0]
pause 200
goto main
Term_RX:
HSERin [dec3 normtemp[0]]
return
The application is simply sending S followed by three digits for normtemp[0] in DEC format, with no carriage returns - However when I click the update button of the application the PIC freezes for around 10 min. I've proved the PIC is responding to the PC app by changing the "S" to "X" (or any other character) which is ignored when the update button is pressed.
Bookmarks