mudassir shah
New Member
Hello;
I am fresh here. I am working on atmega8. I want to read analog voltage from its ADC0 pin. I write code for it in mikroc pro for avr. But it gives me error that “result is not written to adc register because it has been locked.” It reads only first simple and then stopped. I don’t know how to solve it??? Anybody have any idea about it? Circuit and code are attached.
Code is:
i get error in uploading the circuit.
I am fresh here. I am working on atmega8. I want to read analog voltage from its ADC0 pin. I write code for it in mikroc pro for avr. But it gives me error that “result is not written to adc register because it has been locked.” It reads only first simple and then stopped. I don’t know how to solve it??? Anybody have any idea about it? Circuit and code are attached.
Code is:
Code:
// LCD module connections
sbit LCD_RS at PORTD0_bit;
sbit LCD_EN at PORTD1_bit;
sbit LCD_D4 at PORTD2_bit;
sbit LCD_D5 at PORTD3_bit;
sbit LCD_D6 at PORTD4_bit;
sbit LCD_D7 at PORTD5_bit;
sbit LCD_RS_Direction at DDD0_bit;
sbit LCD_EN_Direction at DDD1_bit;
sbit LCD_D4_Direction at DDD2_bit;
sbit LCD_D5_Direction at DDD3_bit;
sbit LCD_D6_Direction at DDD4_bit;
sbit LCD_D7_Direction at DDD5_bit;
// End LCD module connections
unsigned int ADC = 0,adc_result=0;
unsigned char display[7];
void main() {
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"ADC:"); // Write text in first row
ADIE_bit = 1;
ADEN_bit = 1;
ADFR_bit = 0;
ADIF_bit = 0;
ADPS2_bit = 1;
ADPS1_bit = 1;
ADPS0_bit = 1;
ADMUX = 0b01000000;
while(1){
//ADIE_bit = 1;
ADSC_bit = 1;
while(!ADIF_bit);
ADIF_bit = 0;
ADC = (ADCH * 256) + ADCL;
IntToStr(ADC,display);
Lcd_Out(2,1,display);
}
}
i get error in uploading the circuit.
Last edited by a moderator: