Il mio dubbio e' anche capire MKB cosa fa con i registri intco1 e intcon0 quando usa la macro ADC_read(2).
Qualcuno ha esperienze a proposito?
Allego il listato:
program adc2_lcd
'(*
' * Project name:
' adconlcd
' * Copyright:
' © mikroElektronika, 2005 - 2006
' * Revision History:
' 20050312:
' - initial release.
' * Description:
' This code demonstrates how to use library function ADC_read, and library
' procedures and functions for LCD display (4 bit interface)
' * Test configuration:
' MCU: PIC16F877A
' Dev.Board:
' Oscillator: HS, 4.000 MHz
' Ext. Modules: None
' SW: mikroBasic v5.0 or higher
' * NOTES:
' - If you are using EasyPIC4, use provided jumper on top right to connect potentiometer to RA2
' *)
dim ch1 as byte
ch2 as byte
t1 as word
t2 as word
Text1 as char[17]
Text2 as char[17]
tlong1 as longint
tlong2 as longint
main:
PORTB =0 ' clear portb
TRISB =0 ' designate portb as output (LCD is connected to portb)
intcon =0 ' disable all interrupts
Lcd_Init(PORTB) ' initialize (4-bit interface connection)
Lcd_Cmd( LCD_CURSOR_OFF) ' send command to LCD (cursor off)
Lcd_Cmd(LCD_CLEAR) ' send command to LCD (clear LCD)
Text1 ="A/D Aduri" ' assign text to string a
Lcd_Out(1,1, Text1) ' print string a on LCD, 1st row, 1st column
Text2 ="Prova" ' assign text to string a
Lcd_Out(2,1, Text2) ' print string a on LCD, 2nd row, 1st column
OPTION_REG = $80
ADCON1 = $82 ' configure VDD as Vref, and analog channels
TRISA = $FF ' designate porta as input
Delay_ms(2000)
Text1 = "voltage1:" ' assign text to string a
Lcd_Out(1,1,Text1) ' print string a on LCD, 2nd row, 1st column
Lcd_Chr(1,14,"V")
Text2 = "voltage2:" ' assign text to string a
Lcd_Out(2,1,Text2) ' print string a on LCD, 2nd row, 1st column
Lcd_Chr(2,14,"V")
while true
t1 = ADC_read(1) ' get ADC value from 1st channel
tlong1 = t1*5000
t1 = tlong1 >> 10
ch1 = t1 div 1000 ' prepare value for diplay
Lcd_Chr(1,11,48+ch1) ' write ASCII at first row, 9th column
Lcd_Chr(1,12,".")
ch1 = (t1 div 100) mod 10
Lcd_Chr(1,13,48+ch1)
ch1 = (t1 div 10) mod 10
Lcd_Chr(1,14,48+ch1)
ch1 = t1 mod 10
Lcd_Chr(1,15,48+ch1)
delay_ms(1)
t2 = ADC_read(2) ' get ADC value from 2nd channel
tlong2 = t2*5000
t2 = tlong2 >> 10
ch2 = t2 div 1000 ' prepare value for diplay
Lcd_Chr(2,11,48+ch2) ' write ASCII at 2nd row, 9th column
Lcd_Chr(2,12,".")
ch2 = (t2 div 100) mod 10
Lcd_Chr(2,13,48+ch2)
ch2 = (t2 div 10) mod 10
Lcd_Chr(2,14,48+ch2)
ch2 = t2 mod 10
Lcd_Chr(2,15,48+ch2)
delay_ms(1)
wend
end.
Cordiali saluti