OK I have the software Uart working. I also have the hardware USArt working. I just Can't get both to work together. Here is my code.
The problem is the var pressure does not update. IF I reset the pic then it does. Thanks for any advice.
Code: Select all
DEVICE = 18F1220
CLOCK = 16
' include modules
INCLUDE "suart.bas"
INCLUDE "ADC.bas"
INCLUDE "Convert.bas"
INCLUDE "usart.bas"
' create vars
DIM ADVal AS WORD
DIM pressure AS WORD
SUB Read_pressure ()
ADVal = ADC.Read(0) ' this code reads pressure on analog pin 0
ADVal = (ADVal +1) * 500 / 1024 ' this code is math to convert the 10 bit value to voltage
pressure = ADVal * 13.6 ' this math converts voltage to pressure
END SUB
SUB SGLCD_Connect ()
UART.Write (85) ' 'connect to serial GLCD
DELAYMS(50)
UART.Write(170,128) ' adjust SGLCD backlight
UART.Write (186) ' clear the display
DELAYMS(50)
UART.Write (188,17,1," Well Monitor v1.0",0)
DELAYMS (5000)
UART.Write(186)' clear the display
DELAYMS(50)
UART.Write(188,2,1," Powered by SwordFish",0)
DELAYMS(5000)
UART.Write(186)' clear the display
DELAYMS(50)
UART.Write(188,16,5,"PSI:",0)
DELAYMS(50)
UART.Write(255,4,16,16,32,16,255) ' underline PSI
DELAYMS(50)
UART.Write (255,2,0,0,127,63,255) ' draw a rectangle around the outside the glcd
DELAYMS(50)
END SUB
SUB SGLCD_Display()
UART.Write(183) ' use big font to display numbers
DELAYMS(20)
UART.Write (188,12,32,DecToStr(pressure/100),".",DecToStr (pressure,1)," ",0) ' write to SGLCD
DELAYMS (100)
END SUB
SUB PC_Display ()
USART.Write(pressure/100) ' write to PC serial Port
END SUB
SetTX(PORTA.1)
SetMode(umTrue)
SetBaudrate(sbr9600)
SetBaudrate(br9600)
TRISA.1 = 0
TRISA.0 = 1 // configure AN0 as an input
ADCON1 = %11111110 // set analogue input on PORTA.0
SGLCD_Connect
Main_program:
Read_pressure
DELAYMS(50)
SGLCD_Display
DELAYMS (50)
PC_Display
DELAYMS(50)
GOTO Main_program