回复 2楼 peach5460
刚开始学(单位有许多搞51单片机的,我目前能用简单的语句控制单片机电路),我30岁了。感觉从书本上学太耗时,个人认为找个小项目,边做边学会记忆很深刻!
工作原因,经常接触下面的
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
0x76,0x79,0x38,0x3f,0};
uchar temp,xian,deng,tt,tt1,kg,kg1,bai,shi,ge;
uint shu;//大于256,定义整数变量
void xianshi(uchar aa,uchar bb,uchar cc,uchar bai,uchar shi, uchar ge);
void chushi();
void yanshi(uint z);
void main()//主程序
{
chushi();
while(1)
{
if(kg!=1)
{
xianshi(7,6,5,bai,shi,ge);
}
else
xianshi(16,17,18,18,19,20);
}
}
void chushi()
{
shu=432;
temp=0xfe;
P1=temp;
TMOD=0x11;//初始化定时器
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
ET1=1;
TR1=1;
}
void dingshi1()interrupt 1//定时器0
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
tt++;
if(kg1!=1)
{
if(tt==2)
{
tt=0;
temp=_crol_(temp,1);
P1=temp;
}
}
else
{
if(tt%4==0)//4毫秒闪烁
P1=~P1;
if(tt==60)
{
kg=1;
P1=0xff;
TR0=0;
}
}
}
void dingshi0()interrupt 3//定时器1
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
tt1++;
if(tt1==2)//1毫秒
{
tt1=0;
shu--;
bai=shu/100;
shi=shu%100/10;
ge=shu%10;
if(shu==398)
{
TR0=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
kg1=1;
tt=0;
P1=0xff;
TR1=0;//关闭定时器1
}
}
}
void xianshi(uchar aa,uchar bb,uchar cc,uchar bai,uchar shi, uchar ge)//显示函数
{
dula=1;
P0=table[aa];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
yanshi(1);
dula=1;
P0=table[bb];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
yanshi(1);
dula=1;
P0=table[cc];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
yanshi(1);
dula=1;
P0=table[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
yanshi(1);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
yanshi(1);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
yanshi(1);
}
void yanshi(uint z)//延时函数
{
uint x;
for(;z>0;z--)
for(x=110;x>0;x--);
}
[
本帖最后由 奔跑的萝卜 于 2013-3-23 23:56 编辑 ]