sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
unsigned int q=0,*q1[20],frekfencija=30; // 19531=1hz=1s
unsigned int txt[4],txt1[7],txt2[7],prikaz=0;
unsigned int nula;
unsigned int trenutno,kas=100;
unsigned int raz,sum;
unsigned int j;
unsigned int temp_res,dsp;
char i;
void interrupt(){
if(pir1.tmr2if){
pir1.tmr2if=0;
nula++;
tmr2=0;
}
if (nula==frekfencija){
nula=0;
}
}
void def_interupta(void){
gie_bit=1;
peie_bit=1;
pie1.tmr2ie=1;
tmr2on_bit=1;
}
void def_ulaza(void){
TRISA = 255; // PORTA is input
trisc.rc0= 0; // PORTC is output
trisc.rc1= 0;
TRISB = 0; // PORTB is output
portc=0;
porta=0;
portb=0;
}
void def_lcd(void){
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
}
void main() {
ANSEL = 0x04; // Configure AN2 pin as analog
ANSELH = 0; // Configure other AN pins as digital I/O
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
def_interupta();
delay_ms(500);
def_ulaza();
def_lcd();
*q1=ADC_Read(0);
while(1){
for(i=0;i<9;i++)
sum+=q1;
raz=sum/10;
wordtostr(raz,txt);
lcd_out(1,1,txt);
}
}
- - - Updated - - -
hello.
I need to calculate the average value on analog input.The hardvear is good but I can't get the code working.
I even thried to use interrups to take sample in 1s but I didn't give me resoult.
On the display is writen one number all the time(for example 33).
pic 16f887
20MHz
Mikroc v.5.6.1