Chip type : ATmega32
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
*****************************************************/
#include
#include
// Alphanumeric LCD Module functions
// its customization
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include
void main(void)
{
PORTA=0x00;
DDRA=0x00;
PORTB=0x00;
DDRB=0x00;
PORTC=0x00;
DDRC=0xFF;
PORTD=0x00;
DDRD=0xFF;
Analog_init();
// LCD module initialization
lcd_init(16);
while (1)
{
if (ACSR.5 == 1) {
PORTD =0xFF;
}
else {
PORTD =0x00;
}
delay_ms(100);
};
}
//---------------------------- ANALOG COMPARATOR ----------------------//
void Analog_init(void) {
ACSR |= (1 << ACBG); // enable internal reference voltage 1,1V
ACSR |= (1 << ACIE); // enable comparator interrupt
}
void Analog_end(void) {
ACSR |= (1 << ACD);
}
ISR (ANALOG_COMP_vect) {
int ac1 = 0;
int ac2 = 0;
int k = 0;
if (ACO == 0) {
ac2 = ac1;
ac1 = ACO;
}
else {
ac2 = ac1;
ac1 = ACO;
}
k++;
if (k==6) {
ac1=ACO;
if (ac2==ac1) {
DDRC <<1 nbsp="" p=""> }
else {
DDRC <<1 nbsp="" p=""> DDRC +=1;
}
k=1;
}
Analog_end();
get_number(DDRC);
}
//-------------------------- END ANALOG COMPARATOR----------------------//
1>1>
No comments:
Post a Comment