如何解决为什么屏幕每秒重置一次?
我正在尝试在大学完成我的项目,但我找不到屏幕一秒钟后重置的原因。该项目应该是秒表,显示分钟和秒。我需要有 3 个按钮:1. startstop 2.set 分钟 3. 设置秒,但它应该可以工作.. 我不知道为什么它在更改后设置“0000”秒...
项目写入ATMEGA32处理器
#include <avr/io.h>
#include <avr/interrupt.h>
#define F_cpu 16000000
#include <util/delay.h>
#define segment_DDR DDRA //porty dotyczace wyswietlacza
#define segment PORTA
#define digit_DDR DDRB
#define digit PORTB
#define keys_DDR DDRC //porty dotyczace klawiszy
#define keys_PULLUP PORTC
#define keys_PIN PINC
#define key1 0
#define key2 1
#define key3 2
volatile uint8_t button1=0,button2=0,button3=0,startstop=0; //deklaracja zmiennych
uint8_t seg7[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xd8,0x80,0x90}; //tablice
volatile uint8_t data[] = {0,0};
ISR(TIMER0_OVF_vect) //timer0
{
static uint8_t i=0,dot=0,mig=0; //odswiezanie wyswietlacza
digit |= (1<<i);
if(i++==3) i=0;
segment = seg7[data[i]];
if((i==3) && (startstop==1) && (dot++==50))
{
dot=0;
mig ^= 1;
}
if (i==3)
{
segment = seg7[data[i]] & 0x7f;
segment |= (mig<<7);
}
digit &= ~(1<<i);
//button startstop
if (!(keys_PIN & (1<<key1)))
{
switch(button1)
{
case 0:
button1=1;
break;
case 1:
button1=2;
break;
}
}
else
{
switch(button1)
{
case 3:
button1=4;
break;
case 4:
button1=0;
break;
}
}
//przycisk_m
if (!(keys_PIN & (1<<key2)))
{
switch(button2)
{
case 0:
button2=1;
break;
case 1:
button2=2;
break;
}
}
else
{
switch(button2)
{
case 3:
button2=4;
break;
case 4:
button2=0;
break;
}
}
//przycisk_h
if (!(keys_PIN & (1<<key3)))
{
switch(button3)
{
case 0:
button3=1;
break;
case 1:
button3=2;
break;
}
}
else
{
switch(button3)
{
case 3:
button3=4;
break;
case 4:
button3=0;
break;
}
}
}
ISR(TIMER1_OVF_vect) //timer1
{
}
int main(void)
{
keys_PULLUP |= (1<<key1)|(1<<key2)|(1<<key3); //pullup
keys_DDR &= ~((1<<klawisz1)|(1<<klawisz2)|(1<<klawisz3));
segment_DDR = 0xff;
digit_DDR |= 0x0ff;
digit |= 0x0ff;
segment = 0xff;
TCCR0 = (1<<CS01);
TCCR1B = (1<<CS12)|(1<<WGM12);
TimsK = (1<<TOIE0)|(1<<OCIE1A);
OCR1A = 62500;
sei();
while (1)
{
if (button1==2)
{
startstop = !startstop;
button1 = 3;
}
if(startstop!=1 && button2==2)
{
if (data[3]++==9)
{
data[3]=0;
if (data[2]++==6)
{
data[2]=0;
}
}
button2=3;
}
if(startstop!=1 && button3==2)
{
if (data[1]++==9)
{
data[1]=0;
if (data[0]++==6)
{
data[0]=0;
}
}
button3=3;
}
while(startstop==1)
{
if (data[3]++==9)
{
data[3]=0;
if (data[2]++==6)
{
data[2]=0;
if (data[1]++==9)
{
data[1]=0;
if (data[0]++==6)
{
data[0]=0;
}
}
}
}
_delay_ms(1000);
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。