'***************************************************************************** '* MICROCODE STUDIO TIPS * '* * '* (1) : To get context sensitive help, move your cursor to a PICBasic * '* : command and then press F1. * '* (2) : Program assumes the PIC is running at 4MHz. To change the default * '* : setting (for example, to 20MHz) simply add DEFINE OSC 20 at the * '* : top of your program. * '* 16F876A 4 line Display, 4 analogue Inputs * '* Micro code studio 3.0.0.5 '* programmer PICKIT 2 'This sample program is supplied courtesy of microEngineering Labs Inc * '***************************************************************************** ' PicBasic Pro program to display result of ' 8-bit A/D conversion on LCD ' Connect analog input to channel-0 (RA0) DEFINE LCD_DREG PORTC DEFINE LCD_DBIT 4 DEFINE LCD_RSREG PORTC DEFINE LCD_RSBIT 0 DEFINE LCD_EREG PORTC DEFINE LCD_EBIT 3 DEFINE LCD_LINES 4 DEFINE LCD_COMMANDUS 2000 DEFINE LCD_DATAUS 50 DEFINE osc 4 ' Define ADCIN parameters Define ADC_BITS 8 ' Set number of bits in result Define ADC_CLOCK 1 ' Set clock source (3=rc) Define ADC_SAMPLEUS 50 ' Set sampling time in uS CMCON = 7 CVRCON = 0 adval1 var byte adval2 var byte adval3 var byte adval4 VAR BYTE ' Create adval to store result TRISC = %00000000 TRISA = %11111111 ' Set PORTA to all input TRISB = %00000000 ' Set PORTB to all output ADCON1 = %00000010 ' Set PORTA analog LOW Portc.2 Pause 500 ' Wait .5 second loop: ADCIN 0, adval1 ' Read channel 0 to adval 'SEROUT PORTB.0,N1200,[adval1] 'This doesn´t compile SEROUT PORTB.0,5,[adval1] 'this compiles altough N1200 and 5 are the same gosub Bargraph1 LCDOUT $FE, 2 ADCIN 1, adval2 ' Read channel 0 to adval Lcdout $fe,$C0 ' Move cursor to beginning of second line Lcdout "Wert2: ", DEC adval2 ' Display the decimal value works ADCIN 2, adval3 ' Read channel 0 to adval Lcdout $fe,$94 ' Move cursor to beginning of third line Lcdout "Wert3: ", DEC adval3 ' Display the decimal value jumps in the middle ADCIN 3, adval4 ' Read channel 0 to adval LCDOUT $FE,$D4 'jumps in the middle LCDOUT "Wert4: ", DEC adval4 Pause 100 ' Wait .1 second Goto loop ' Do it forever Bargraph1: IF (adval1 <= 15) Then LCDOUT $FE,1 LCDOUT "Kalt" Endif IF (adval1 > 15) and (adval1 <= 20 ) then LCDOUT $FE,1,255 endif if (adval1 > 20) and (adval1 <= 25 ) then LCDOUT $FE,1,255,255 endif if (adval1 > 25) and (adval1 <= 30 ) then LCDOUT $FE,1,255,255,255 endif if (adval1 > 30) and (adval1 <= 35 ) then LCDOUT $FE,1,255,255,255,255 endif if (adval1 > 35) and (adval1 <= 40 ) then LCDOUT $FE,1,255,255,255,255,255 endif if (adval1 > 40) and (adval1 <= 45 ) then LCDOUT $FE,1,255,255,255,255,255,255 endif if (adval1 > 45) and (adval1 <= 50 ) then LCDOUT $FE,1,255,255,255,255,255,255,255 endif if (adval1 > 50) and (adval1 <= 55 ) then LCDOUT $FE,1,255,255,255,255,255,255,255,255 endif if (adval1 > 55) and (adval1 <= 60 ) then LCDOUT $FE,1,255,255,255,255,255,255,255,255,255 endif if (adval1 > 60) and (adval1 <= 65 ) then LCDOUT $FE,1,255,255,255,255,255,255,255,255,255, 255 endif if (adval1 > 65) and (adval1 <= 70 ) then LCDOUT $FE,1,255,255,255,255,255,255,255,255,255, 255,255 endif if (adval1 > 70) and (adval1 <= 75 ) then LCDOUT $FE,1,255,255,255,255,255,255,255,255,255, 255,255,255 endif if (adval1 > 75) and (adval1 <= 80 ) then LCDOUT $FE,1,255,255,255,255,255,255,255,255,255, 255,255,255,255 endif if (adval1 > 80) and (adval1 <= 85 ) then LCDOUT $FE,1,255,255,255,255,255,255,255,255,255, 255,255,255,255,255 endif if (adval1 > 85) and(adval1 <= 90 ) then LCDOUT $FE,1,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255 endif if (adval1 > 90) then LCDOUT $FE,1 LCDOUT "GEFAHR" TOGGLE portC.2 else LOW PORTC.2 endif return End