此帖出自Microchip MCU论坛
最新回复
//timercount ext_6-2
#include
#include
#include
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include
unsigned char TEXT[2][16];
unsigned char hour = 0;
unsigned char min = 0;
unsigned char sec = 0;
unsigned char n = 0;
bit flag = 0;
bit flag_1 = 0;
unsigned char key;
void Display_switch(void)
{
key = PIND & 0x03;
switch(key){
case 0b00000010:
delay_ms(150);
if(flag_1 == 0)
{
flag_1 = 1;
}
else
{
flag_1 = 0;
}
break;
case 0b00000001:
sec = 0;
min = 0;
hour = 0;
n = 0;
if(flag_1 == 1)
flag = 0;
break;
default: break;
}
}
--------------------------------------------
void Display_count(void)
{
if(sec >= 100){
sec = 0;
min++;
if(min >= 60){
min = 0;
hour++;
if(hour >=60){
hour = 0;
n++;
if(n > 12){
n = 0;
}
}
}
}
}
void Display_LCD(void)
{
lcd_clear();
sprintf(TEXT[0],"%2d :%2d", n, hour);
lcd_gotoxy(0,0);
lcd_puts(TEXT[0]);
sprintf(TEXT[1],":%2d :%2d", min,sec);
lcd_gotoxy(0,1);
lcd_puts(TEXT[1]);
}
void main()
{
DDRC = 0xff;
PORTC =0xff;
DDRD = 0x00;
TCCR1A = 0x00;
TCCR1B = 0x0D;
OCR1A = 156;
TIMSK = 0x10;
SREG = 0x80;
lcd_init(16);
#asm("sei")
while(1)
{
Display_switch();
Display_count();
if(flag == 1){
flag = 0;
Display_LCD();
}
};
}
interrupt [TIM1_COMPA] void timer1_compa_isr(void)
{
if(flag_1 == 1){
sec++;
}
flag = 1;
}
详情
回复
发表于 2013-6-14 23:34
| ||
|
||
| |
|
|
回复 沙发 gh131413 的帖子
此帖出自Microchip MCU论坛
| ||
|
||
| |
|
|
| |
|
|
| |
|
|
| |
|
|
回复 7楼 gh131413 的帖子
此帖出自Microchip MCU论坛
点评 | ||
|
||
| |
|
|
回复 8楼 lcofjp 的帖子
此帖出自Microchip MCU论坛
| ||
|
||
此帖出自Microchip MCU论坛
点评赞赏 | ||
|
||
| |
|
|
| |
|
|
回复 13楼 gh131413 的帖子
此帖出自Microchip MCU论坛
点评 | ||
|
||
回复 14楼 cat3902982 的帖子
此帖出自Microchip MCU论坛
| ||
|
||
| |
|
|
我用的这个屏,看PDF
此帖出自Microchip MCU论坛
| ||
|
||
| |
|
|
此帖出自Microchip MCU论坛
| ||
|
||
以前利用atmega128 做的秒表,lcd是最一般的2*8的, 希望对你有帮助
此帖出自Microchip MCU论坛
点评 | ||
|
||
浏览过的版块 |
曾经的版主且威望大于2000,或对EEWORLD论坛有突出贡献的坛友
EEWorld Datasheet 技术支持