#include
#define uchar unsigned char
#define uint unsigned int
#pragma interrupt_handler power_off:2
#define EN_ PORTB&=~BIT(2)
#define EN PORTB|=BIT(2)
#define LE PORTB|=BIT(3) //高电平选通573
#define LE_ PORTB&=~BIT(3) //低电平锁存573
#define LEDEN PORTB|=BIT(4) //高电平选通led10
#define LEDEN_ PORTB&=~BIT(4)//低电平禁止led10
#define RONCS PORTB|=BIT(5) //高电平选通rom
#define ROMCS_ PORTB&=~BIT(5) //低电平禁止rom
#define KEYEN DDRD|=BIT(7) //高电平选通导航键盘
#define KEYEN_ DDRD&=~BIT(7) //低电平禁止导航键盘
#define MAC_ PORTD&=~BIT(0)//开启蜂鸣器
#define MAC PORTD|=BIT(0) //关闭蜂鸣器
#define CE PORTD|=BIT(1)
#define CE_ PORTD&=~BIT(1)
#define IO PORTD|=BIT(2)
#define IO_ PORTD&=~BIT(2)
#define SCLK PORTD|=BIT(3)
#define SCLK_ PORTD&=~BIT(3)
#define DATC PORTC
extern dat[]={1,9,3,7};
uchar tab1[4][4][16]={
{{"选项一:涂鸦板 "},{"选项二:摇奖机 "},{"选项四:贪吃蛇 "},{"选项三:退出游戏"}},
{{"涂鸦板使用规则—"},{"移动使用导航键 "},{"提放笔:按'ok'键"},{"返回请按:'B' 键"}},
{{"摇奖机使用规则—"},{" 'ok'键开始 "},{" 'ok'键停止 "},{"得分为最终停止值"}},
{{"贪吃蛇使用规则—"},{"移动使用导航键 "},{"结束游戏按:'B'键"},{"吃闪动的点会变长"}},
};
extern png[5][8]={
{0x00,0x40,0x42,0x7E,0x7E,0x42,0x40,0x00},
{0x0C,0x12,0x22,0x44,0x44,0x22,0x12,0x0C},
{0x02,0x3E,0x42,0x40,0x40,0x42,0x3E,0x02},
{0x00,0x04,0x02,0xA2,0x12,0x0C,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
};
const xy[]={0x80,0x90,0x88,0x98};
const xy3[]={0x83,0x93,0x8b,0x9b};
const tuan[]={0x05,0x00,0x0e,0x0f};
const tab_f[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xD8,0x80,0x90};
const wela_f[]={0x01,0X02,0X04,0X08};
uchar dat_yj=0,dat_yj1=99,ten_f=0;
extern dat_d[]={2,0,1,1,10,1,1,10,1,9};
extern time[]={1,2,10,0,0,10,0,0};
extern tem[]={0,0,0,0};
extern lum[]={0,0,0,0,0};
extern vol[]={0,0,0,0};
uchar dat_f=0x00,ILU=0,ILU1=0,tyx=0x00,tyy=0x00,tyb=0,yj_f=0,yj_y=0,yj_y1=0;
uchar flag=0x00,flag_right=0x00,dat_k=0x00,sleep=0;//flag=0,主菜单,1涂鸦,2摇奖机,3音乐4电子书9关机
void delay(uint zip)
{
zip=zip*10;
while(zip--);
}
void delayms(uint zip)
{
uint rar;
for(;zip>0;zip--)
for(rar=600;rar>0;rar--);
}
void reset()//任何子程序退出处理
{
PORTA=0X00;
DDRC=0X00;
LE_;
ROMCS_;
LEDEN_;
KEYEN_;
PORTD|=BIT(7);
}
void dat_san()
{
dat[0]=dat_yj0/10;
dat[1]=dat_yj;
dat[2]=dat_yj10/10;
dat[3]=dat_yj1;
}
void dat_show()
{
uchar i;
DDRB=0XFF;LE;DDRC=0Xff;DDRA=0XFF;
dat_san();
for(i=0;i<4;i++)
{
LE;
PORTA=wela_f[i];
LE_;
PORTA=0X00;
PORTC=tab_f[dat[i]];
delay(100);
DATC=0Xff;
}
reset();
}
void write_com(uchar com)
{
PORTB&=~BIT(0);
PORTB&=~BIT(1);
LE;
PORTA=com;
LE_;
PORTA=0X00;
PORTB|=BIT(2);
delay(1);
PORTB&=~BIT(2);
delay(3);
}
void write_dat(uchar dat)
{
PORTB|=BIT(0);
PORTB&=~BIT(1);
LE;
PORTA=dat;
LE_;
PORTA=0X00;
PORTB|=BIT(2);
delay(1);
PORTB&=~BIT(2);
delay(3);
}
void init()
{
LE;
write_com(0X38);//设置16*2显示,5*7点阵,8位数据口
delay(5);
write_com(0X0c);//0000 1(100),开显示,不显光标,不闪光标
delay(5);
write_com(0X06);//0000 01(10),指针加1,整屏不移
delay(5);
}
void choose_flag()
{
uchar i;
for(i=0;i<4;i++)
{
write_com(xy3[i]);
delay(4);
if(flag==i)write_dat(0x12);
else write_dat(0x20);
delay(5);
}
}
void printf(uchar ovi)
{
uchar ovm,ovp;
init();
for(ovm=0;ovm<4;ovm++)
{
write_com(xy[ovm]);
delay(5);
for(ovp=0;ovp<16;ovp++)
{
write_dat(tab1[ovi][ovm][ovp]);
delay(5);
}
}
if(flag_right==0)choose_flag();
reset();
}
void clean()
{
uchar pp,qq;
init();
for(pp=0;pp<4;pp++)
{
write_com(xy[pp]);
delay(10);
for(qq=0;qq<17;qq++)
{
write_dat(0x20);
delay(6);
}
}
delay(20);
reset();
}
void init_128()
{
write_com(0x30);//基本指令集
write_com(0x0f);//0000,1100 后两位为设置光标
}
void write_1302(uchar add,uchar dat)
{
uchar i;
}
uchar read_1302(uchar add)
{
uchar i,temp;
return temp;
}
void init_130()
{
write_1302(0x84,0x00);
write_1302(0x80,0x00);
write_1302(0x90,0xa0);
}
void brush()
{
time[7]=read_1302(0x81);
time[6]=read_1302(0x81)/16;
time[4]=read_1302(0x83);
time[3]=read_1302(0x83)/16;
time[1]=read_1302(0x85);
time[0]=read_1302(0x85)/16;
dat_d[9]=read_1302(0x87)/16;
dat_d[8]=read_1302(0x87);
dat_d[6]=read_1302(0x89)/16;
dat_d[5]=read_1302(0x89);
dat_d[3]=read_1302(0x8d)/16;
dat_d[2]=read_1302(0x8d);
}
void sends(uchar addxy,uchar *str)
{
uchar temp;
init();
write_com(xy[addxy-1]);
temp=*str;
while(temp!=0x00)
{
write_dat(temp);
temp=*(++str);
delay(4);
}
reset();
}
void ten_led(uchar t_f)
{
LE;
DDRD&=~BIT(7);
if(t_f>0)if(ten_f>9)ten_f=0;
if(t_f<1)if(ten_f<1)ten_f=10;
if(t_f<1)ten_f--;
if(ten_f<8)PORTA=BIT(ten_f);
DDRC=0XFF;
if(ten_f==8)PORTC|=BIT(0);
if(ten_f==9)PORTC|=BIT(1);
PORTB|=BIT(4);
if(t_f>0)ten_f++;
delay(100);
reset();
}
void png_show()
{
uchar i;
const tab[]={0xfe,0xfd,0xfb,0xF7,0xef,0xdf,0xbf,0x7F};
PORTC=0XFF;
for(i=0;i<8;i++)
{
PORTB|=BIT(3);
PORTA=tab[i];
PORTB&=~BIT(3);
PORTA=png[ILU][i];
delay(250);
PORTA=0X00;
}
if(flag_right==0)ILU1++;
if(ILU1==400){ILU1=0;ILU++;}
if(ILU>4)ILU=0;
reset();
}
void printf1()
{
uchar i;
LE;
init_128();
sends(0x80,"DATA:");
for(i=0;i<10;i++)
{
write_dat(dat[i]+0x30);
}
sends(0x90,"TIME:");
for(i=0;i<8;i++)
{
write_dat(time[i]+0x30);
}
sends(0x88,"LUMEN:");
for(i=0;i<5;i++)
{
write_dat(lum[i]+0x30);
}
sends(0," lm");
sends(0x98,"");
for(i=0;i<4;i++)
{
write_dat(tem[i]+0x30);
if(i==1)sends(0,".");
}
sends(0," ℃");
for(i=0;i<4;i++)
{
write_dat(vol[i]+0x30);
if(i==1)sends(0,".");
}
sends(0," V");
reset();
}
void key_init()
{
LE;
PORTA=0X00;
LE_;
KEYEN;
PORTD&=~BIT(7);
DDRC=0X00;
PORTC=0XFF;
}
uchar diskey()
{
key_init();
if(PINC==0XFF);
else
{
MAC_;
dat_k=PINC;
while(PINC!=0XFF){{dat_show();png_show();};MAC;DDRC=0X00;key_init();};
}
reset();
return dat_k;
}
void power_down()
{
delay(100);
clean();
sends(2," Good_bye!");
sends(3,"Made_from_CuAuAl");
PORTD|=BIT(5);
OCR1A=90000;
OCR1B=50;
delayms(6000);
PORTD&=~BIT(5);
clean();
asm("sleep");
}[page]
void deal_keym()//主菜单处理
{
if(dat_k==247){if(flag<1)flag=3;else flag--;dat_k=0;printf(flag_right);}
if(dat_k==127){if(flag>2)flag=0;else flag++;dat_k=0;printf(flag_right);}
if(dat_k==223){if(flag==3)power_down();{flag_right=flag+1;dat_k=0;printf(flag_right);}}
if(dat_k==191){flag_right=10;flag=10;dat_k=0;};
if(dat_k==239){flag_right=0;flag=0;dat_k=0;};
}
void if_back()//是否返回
{
DDRD&=~BIT(6);
PORTD|=BIT(6);
if(!(PIND&0X40))flag_right=0;
}
void tuya()
{
ILU=4;
if(tyb)png[ILU][tyx]|=BIT(tyy);
if(!tyb)png[ILU][tyx]&=~BIT(tyy);
if(dat_k==191){if(tyx<7)tyx++;dat_k=0;}
if(dat_k==239){if(tyx>0)tyx--;dat_k=0;}
if(dat_k==127){if(tyy<7)tyy++;dat_k=0;}
if(dat_k==247){if(tyy>0)tyy--;dat_k=0;}
if(dat_k==223){tyb=!tyb;dat_k=0;}
if(tyb)ten_led(1);
if(!tyb)ten_led(0);
}
void yj()
{
if(dat_k==223){yj_f++;dat_k=0;if(yj_f==2){yj_y=0;yj_y1=0;}}
if(yj_f>2)yj_f=0;
if(yj_f==0)dat_yj=0;
if(yj_f==1){dat_yj++;dat_yj++;dat_yj1--;dat_yj1--;dat_yj1--;}
if(dat_yj>98)dat_yj=0;
if(dat_yj1<6)dat_yj1=99;
if(yj_f==2)if(yj_y1<1)
{
yj_y1=yj_y++;
dat_yj++;dat_yj++;
dat_yj1--;dat_yj1--;
}
if(yj_f==2)if(yj_y<16)if(yj_y1>0)yj_y1--;
if(yj_f==2)ten_led(0);
if(yj_f==1)ten_led(1);
}
void dis_show()
{
uchar i=50;
if(!tyb&flag_right==1){png[ILU][tyx]|=BIT(tyy);}
printf(flag_right);
while(i--)
{
dat_show();
png_show();
if_back();
dat_f=diskey();
if(flag_right==0)deal_keym();
if(flag_right==1)tuya();
if(i<30)if(!tyb&flag_right==1){png[ILU][tyx]|=BIT(tyy);}
if(flag_right==2)yj();
MAC;
if(flag_right==10)printf1();
}
}
void power_off()
{
clean();
sends(2," Welcome");
sends(3," Hi_The_Boy!");
PORTD|=BIT(5);
delayms(5000);
//clean();
// PORTD&=~BIT(5);
WDTCR=0X18;
}
void main()
{
MCUCSR|=BIT(7);
MCUCSR|=BIT(7);
/////////////////
DDRB=0X3F;
DDRD|=BIT(4)|BIT(5)|BIT(7);
DDRD&=~BIT(2);
PORTD|=BIT(2);
//////////////////
TCCR1A=0X23;
TCCR1B=0X1d;
OCR1A=6000;
OCR1B=100;
/////////////////
EN;ROMCS_;LEDEN_;LE;
/////////////////*
MCUCR&=0X20;
GICR|=BIT(6);
SREG|=BIT(7);
///////////////
PORTD|=BIT(5);
//////////////////
DDRD|=BIT(0);
PORTD|=BIT(0);
printf(0);
while(1)
{
MCUCR|=BIT(6);
dis_show();
brush();
}
}
上一篇:ARM·微处理器的编程模型
下一篇:AVR单片机中的中断嵌套
推荐阅读最新更新时间:2024-03-16 14:40