#include <mega16.h>
#include <delay.h>
#include <stdio.h>
volatile unsigned long latch=0;
volatile unsigned char output_f=0;
volatile unsigned char temp=0;
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x18 ;PORTB
#endasm
#include <lcd.h>
typedef unsigned char byte;
byte command_addr;
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
if(!(PIND&(1<<PIND2)))
{
if(TCCR0==0) //debounce
{
TCNT0=0;
//start timer 0
TCCR0=0x01; //clkio/8
PORTA.0=0;
PORTC.0=1;
PORTC.1=1;
}
}
}
// External Interrupt 1 service routine
interrupt [EXT_INT1] void ext_int1_isr(void)
{
if(!(PIND&(1<<PIND3)))
{
if(TCCR0!=0) //debounce
{
//stop timer
TCCR0=0;
latch+=TCNT0;
PORTA.0=1;
PORTC.0=0;
PORTC.1=0;
output_f=1;
}
}
}
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
latch+=0x100;
}
// Declare your global variables here
void output(unsigned long latch)
{
output_f=0;
delay_ms(10);
lcd_init(16);
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("#Time parameter#");
delay_ms(500);
lcd_clear();
lcd_gotoxy(0,0);
command_addr=0b10000000;
temp=latch/10000000;
lcd_write_byte(command_addr,0x30+temp);
latch=latch-temp*10000000;
temp=latch/1000000;
lcd_write_byte(command_addr+1,0x30+temp);
latch=latch-temp*1000000;
temp=latch/100000;
lcd_write_byte(command_addr+2,0x30+temp);
latch=latch-temp*100000;
temp=latch/10000;
lcd_write_byte(command_addr+3,0x30+temp);
latch=latch-temp*10000;
temp=latch/1000;
lcd_write_byte(command_addr+4,0x30+temp);
latch=latch-temp*1000;
temp=latch/100;
lcd_write_byte(command_addr+5,0x30+temp);
latch=latch-temp*100;
temp=latch/10;
lcd_write_byte(command_addr+6,0x30+temp);
latch=latch-temp*10;
temp=latch/1;
lcd_write_byte(command_addr+7,0x30+temp);
latch=latch-temp*1;
}
void main()
{
// Declare your local variables here
//byte command_addr;
PORTA=0xFF;
DDRA=0xFF;
PORTB=0xFF;
DDRB=0x00;
PORTC=0xFF;
DDRC=0xFF;
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 1000.000 kHz
//TCCR0=0x02;
//TCNT0=0x00;
OCR0=0x00;
MCUCR&=0xf0;
MCUCR|=(1<<ISC11)|(0<<ISC10)|(1<<ISC01)|(0<<ISC00);
GICR|=(1<<INT0)|(1<<INT1);
//TIMSK=0x00;
MCUCSR=0x00;
GIFR=0xC0;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x01;
TIFR=0x00;
PORTC=0x00;
// Global enable interrupts
#asm("sei")
while (1)
{
// Place your code here
if(output_f) output(latch);
};
}
char buffer[20];
char bp=0;
while(latch)
{
buffer[bp++]='0'+latch%10;
latch/=10;
}
while(bp)
lcd_write_byte(command_addr++,buffer[--bp]);
if(output_f) output(latch);
if(output_f) { output(latch); latch=0; }
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.