阅读:1692回复:4
AVR单片机问题请教#include <mega16.h> #include <stdlib.h> #include <delay.h> // Alphanumeric LCD Module functions #asm .equ __lcd_port=0x1B ;PORTA #endasm #include <lcd.h> unsigned char flag=0,lcdbuf[5]={0},lcdbuf1[5],dsec=0,min1=0,sec1=0,*p=lcdbuf1; unsigned char scan_key(void) { unsigned char i,temp; PORTB=0x00; DDRB=0x00; temp=PINB&0x0f; if(temp!=0x0f) { delay_ms(15); temp=PINB&0x0f; if(temp!=0x0f) temp&=0x0f; } return temp; } unsigned char keypad(void) { unsigned char temp1,temp2; temp1=scan_key(); do temp2=scan_key(); while(temp1==temp2); return temp1; } interrupt [TIM1_OVF] void timer1_ovf_isr(void) { TCNT1H=0xF9; TCNT1L=0xE6; if(flag) { dsec++; if(dsec>9) { dsec=0; sec1++; if(sec1>59) { sec1=0; min1++; if(min1>59) { min1=0; sec1=0; dsec=0; } } } lcdbuf[4]=dsec; lcdbuf[3]=sec1%10; lcdbuf[2]=sec1/10; lcdbuf[1]=min1%10; lcdbuf[0]=min1/10; } } void lcd_timer(void) { unsigned char i; lcd_clear(); for(i=0;i<6;i++) { itoa(lcdbuf,&lcdbuf1); if(i<2) { lcd_gotoxy(i+1,1); lcd_puts(&lcdbuf1); } else if((i<4)&(i>1)) {lcd_gotoxy(i+2,1);lcd_puts(&lcdbuf1);} else if(i==4) {lcd_gotoxy(i+3,1);lcd_puts(&lcdbuf1);} } lcd_gotoxy(3,1);lcd_putchar(':');lcd_gotoxy(6,1);lcd_putchar(':'); } void main(void) { TCNT1H=0xF9; TCNT1L=0xE6; TCCR1A=0x00; TCCR1B=0x04; MCUCR=0x00; MCUCSR=0x00; lcd_init(8); #asm(\"sei\") flag=0; while (1) { // Place your code here keyval=keypad(); switch(keyval) { case 0x0E:{flag^=1;break;} case 0x0D:{flag=0;dsec=0;sec1=0;min1=0; for(i=0;i<5;i++) lcdbuf=0; break;} default:break; } lcd_timer(); }; } |
|
沙发#
发布于:2005-05-08 14:40
贴了一大段代码,问题呢?
|
|
板凳#
发布于:2005-05-08 20:32
此为一秒表程序,B0口接启动/停止键,B1口接清零键,A口接8段LCD,但调试不通,想请教高手是何原因?
|
|
地板#
发布于:2005-06-03 12:21
没有注释,没有函数说明的程序看着都烦了
|
|
地下室#
发布于:2005-07-19 10:47
怎么调试不通,问题是什么?说得清楚一点,不然别人也摸不着头脑.
|
|