I managed to send message to PC and added sensor reading(working in a separate program), but now I have strange reading on my temperature and light sensors. kindly check my code.
regards,Code:'DEFINE LOADER_USED 1 ' using bootloader Include "modedefs.bas" DEFINE OSC 20 ' running at 20 MHZ ' PORT setting ' ============ ' TRISC=%10000000 ' RC.7 => USART RX pin set to input ' all other pin set to output ' TRISB=0 ' RB<7:0> set to output ' USART setting ' ============= ' Since we will not use HSERIN/HSEROUT, we must ' write directly to internal PIC register ' TXSTA=$24 ' enable transmit and SPBRGH=1 RCSTA=$90 ' Enable USART and continuous receive SPBRG=129 ' BAUD RATE = 9600 BAUDS ' Interrupt definition ' ==================== ' PIE1.5 =1 ' enable USART receive interrupt INTCON.6 =1 ' enable peripheral interrupt ' Alias definition ' ================ ' RCIF var PIR1.5 ' receiver interrupt StatusLED var PORTB.0 ' the LED who show a 'running process' UserLED1 var PORTB.1 ' the LED1 that user want to control UserLED2 var PORTB.2 ' the LED2 that user want to control UserLED3 var PORTB.3 ' the LED3 that user want to control UserLED4 var PORTB.4 ' the LED4 that user want to control ' Variable definition ' =================== ' Delay var word ' DataIn var byte ' use to store RCREG content Discard var byte ' use to erase RCREG register ' Hardware/software initialisation ' ================================ ' PORTB=0 ' clear PORTB on interrupt goto USARTInterrupt '------------------------------------------------------------------------------ DEFINE ADC_BITS 8 ' Set A/D for 8-bit operation DEFINE ADC_CLOCK 1 ' Set A/D clock Fosc/8 DEFINE ADC_SAMPLEUS 50 ' Set A/D sampling time @ 50 uS adval Var Byte ' Create adval to store result TRISA = %11111111 ' Set PORTA to all input ADCON1 = %00000011 ' Set PORTA.0,1,2,5 = A/D, PortA.3 = +Vref 'ADCON1 = %00000010 ' Set PORTA analog '--------Variables-------------------------------------------------------------- light var WORD samples VAR WORD ' Multiple A/D sample accumulator sample VAR BYTE ' Holds number of samples to take temp VAR BYTE ' Temperature storage samples = 0 ' Clear samples accumulator on power-up samples2 var word sample2 VAR BYTE samples2 = 0 pause 500 Start: ' Main program loop that make the user happy to ' see a LED flashing to mean that something is ' running ' toggle statusled Pause 100 FOR sample = 1 TO 20 ' Take 20 samples ADCIN 1, temp ' Read channel 0 into temp variable samples = samples + temp ' Accumulate 20 samples PAUSE 100 ' Wait approximately 1/4 seconds per loop NEXT sample temp = (samples/20) Hserout ["Temp=",DEC temp ,"'C" ,13] ADCIN 0, light Hserout ["Light=",DEC light ,13] goto start disable interrupt USARTInterrupt: ' Here's the interrupt routine who will make the user ' much happy by giving him the feeling to have the ' control on the machine when the status of the user ' LED will change ' RCSTA=0 ' Disable serial port AND ' clear possible error (FERR,OERR) datain=RCREG ' Get data while RCif ' wait untill the RCREG is empty discard=RCREG ' by reading it and store result in a wend ' don't care variable select case datain ' What to do with that data??? case "1" ' User selection = 1 userled1=1 ' => Enable the LED case "2" ' User selection =2 userled1=0 ' => disable the LED case "3" ' User selection = 3 userled2=1 ' => Enable the LED case "4" ' User selection =4 userled2=0 ' => disable the LED case "5" ' User selection = 3 userled3=1 ' => Enable the LED case "6" ' User selection =4 userled3=0 ' => disable the LED case "7" ' User selection = 3 userled4=1 ' => Enable the LED case "8" ' User selection =4 userled4=0 ' => disable the LED end select RCSTA=$90 ' Re-enable the serial PORT AND resume ' get out of here enable interrupt
tacbanon




Bookmarks