ورود

View Full Version : سوال: برنامه نویسی کرنومتر با avr



fariba99
سه شنبه 11 شهریور 1393, 01:47 صبح
سلام دوستان.ازتون یک راهنمایی میخواستم.کسی میتونه این برنامه نویسی کرنومتر که شامل سه کلید start.reset.hold میباشد را حوه کارکردش برام توضیح بده؟



-----------------------------------------------------------------




#include <mega8.h>


// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x18 ;PORTB
#endasm
#include <lcd.h>
#include <delay.h>
#include <stdio.h>


unsigned char buffer[24],i=0,c=0;
unsigned int hold[6][4],korno[4],counter;
bit a=1;


void show(char d,int e);


// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
#asm("cli")


TCCR2=0;
TCNT2=0;
counter=0;
korno[3]=korno[2]=korno[1]=korno[0]=0;
delay_ms(100);
a=0;
#asm("sei")


}


// Timer 2 overflow interrupt service routine
interrupt [TIM2_OVF] void timer2_ovf_isr(void)
{
#asm("cli")
counter++;
if (counter>2000) counter=0;
#asm("sei")


}


void main(void)
{
int e=0;
PORTB=0x00;
DDRB=0xFF;


PORTC=0x01;
DDRC=0x00;


PORTD=0x7;
DDRD=0x00;




ASSR=0x00;
TCNT2=0x00;
OCR2=0x00;


// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Rising Edge
// INT1: Off
GICR|=0x40;
MCUCR=0x02;
GIFR=0x40;


// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x40;




// LCD module initialization
lcd_init(16);


// Global enable interrupts
#asm("sei")
show(0,0);
while (1)
{
a=1;c=0;
while(PINC.0);
delay_ms(900);
TCCR2=0x02;
while(PINC.0 && a) {
korno[0]=counter/20;
if (korno[0]>98) {korno[1]++;counter=korno[0]=0;}
if (korno[1]>59) {korno[1]=0;korno[2]++;}
if (korno[2]>59) {korno[2]=0;korno[3]++;}
if (korno[3]>24) {korno[3]=0;}
show(0,0);
if (!PIND.1) {
hold[c][3]=korno[3];
hold[c][2]=korno[2];
hold[c][1]=korno[1];
hold[c][0]=korno[0];
c++;
if (c==6) c=0;
delay_ms(900);
}
};

TCCR2=0;
show(0,0);
delay_ms(800);
while ((PIND.1) & a);
delay_ms(800);
while ((PINC.0) & a) {
if (PIND.1==0) e++;
delay_ms(400);
if (e==6) e=0;
show(1,e);
delay_ms(400);
}
show(0,0);
}
}
void show(char d,int e){
if (!d) {
sprintf(buffer,"%d%d:%d%d:%d%d:%d%d ",korno[3]/10,korno[3]%10,korno[2]/10,korno[2]%10,korno[1]/10,korno[1]%10,korno[0]/10,korno[0]%10);
lcd_gotoxy(0,0);
lcd_puts(buffer);}
else {
sprintf(buffer,"%d%d:%d%d:%d%d:%d%d %d",hold[e][3]/10,hold[e][3]%10,hold[e][2]/10,hold[e][2]%10,hold[e][1]/10,hold[e][1]%10,hold[e][0]/10,hold[e][0]%10,e+1);
lcd_gotoxy(0,0);
lcd_puts(buffer);}
return;
}