|
我按照马老师的半状态机方法写一个按键的程序,可是ICCAVR编译说“cannot initialize ram area" ,不知怎么回事?各位大侠能不能帮我看看?我看过很多遍了,还是不明白哪里出错了。
#include<iom16v.h>
#include<macros.h>
#define uchar unsigned char
#define uint unsigned int
#define state_0 0
#define state_1 1
#define state_2 2
uchar key_10ms_on,j,ime[3];
#pragma interrupt_handler xianshi:20
void xianshi() //2ms定时 ctc
{
if(j++==5)
{
j=0;
key_10ms_on=1;
}
uchar read_key()
{
uchar key_temp,key_return=0;
static uchar key_state=0;
key_temp=PINC;
switch (key_state)
{
case (state_0):
if(!key_temp)key_state=state_1;
break;
case (state_1):
if(!key_temp)
{
key_state=state_2;
}
else key_state=state_0;
break;
case (state_2):
if(key_temp) key_state=state_0;
key_return=1;
}
return key_return;
}
void main()
{
while(1)
{
CLI();
TCCR0 = 0x00;
OCR0 = 0x7c;
TCCR0 = 0x0b; //start timer
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x02; //timer interrupt sources
SEI();
DDRC=0;//按键连接的C口设为输入
time[0]=12,time[1]=23,time[2]=35;
if(key_10ms_on)
{
key_10ms_on=0;
if(read_key())
{
if(++time[1]>=59) //这里本来是按键修正分钟的。。
{
time[1]=0;
time[0]++;
}
}
}
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|