📄 hardwarecprogram.txt
字号:
频率计程序
#include<reg51.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
uint t1oc=20; //5000;
uint count=0;
uchar precount=0;
uchar tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //共阳段码
uchar buf[4]={0,0,0,0,};
void Delay1(uint i)
{
while(i--)
{
uchar j;
for(j=0;j<100;j++)
;
}
}
void display(uint dis)
{
// dis=1234;
buf[0]=dis/1000;
buf[1]=dis%1000/100;
buf[2]=dis%100/10;
buf[3]=dis%10;
while(1)
{
P1=0xfe;
P0=tab[buf[0]];
Delay1(4);
P1=0xfd;
P0=tab[buf[1]]|0x80;
Delay1(4);
P1=0xfb;
P0=tab[buf[2]];
Delay1(4);
P1=0xf7;
P0=tab[buf[3]];
Delay1(4);
P1=P2|0x0f;
P0=0x00;
}
}
void t1int() interrupt 3
{
TR1=1;
t1oc--;
TH1=0x4c; //72;//56;
TL1=0x00; //72;//56;
if(t1oc==0)
{
t1oc=20; //5000;
precount=count;
count=0;
}
}
void int0int() interrupt 0
{
EX0=1;
count++;
}
void main(void)
{
TMOD=0x10; //0x20;
TH1=0x4c; //72;//56;
TL1=0x00; //72;//56;
EA=1;
EX0=1;IT0=1;
ET1=1;
TR1=1;
while(1)
{
display(precount);
}
}
目标: 显示缓冲区DisBuf中的数 "Good"
2005年2月20日, 成都信息工程学院通信工程系, 郑郁正
程序功能描述: 多彩的世界,变化无穷
实现方法: 控制单片机左右两排发光二极管
注意事项:运行本程序时,拨码开关 SW1. SW2 全部拨到'OFF'位置(即左边).
如果LED6、LED7和LED8不工作,按一下S2和S3即可
工作方式控制:按键K1、K2、K3和K4可做出不同的显示。
*/
#include <reg52.h> //该头文档描述单片机所有特殊功能寄存器的称名,程序中可直接使用,比喻'P1'
void delayMs( unsigned int tc ); //延时毫秒的函数
char kbhit( void );
char getKey( void );
code unsigned char LedHexCode[]=
{
//0 1 2 3 4 5 6 7
0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,
//8 9 a b c d e f
0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71,
//- H L P o
0x40, 0x76, 0x38, 0x73, 0x5c,
};
unsigned char DisBuf[4]={6,20,20,13};
void main( void ) //一个工程项目必须有一个main函数,并且只能有一个main函数
{
char keyVal=0;
char dots=0;
while( 1 ) //永远为真, 也就是重复运行下面括号中的所有语句,直到永远永远
{
delayMs( (keyVal+1)*10 );
if( kbhit() ) //如果有键按下返回非0值
keyVal=getKey(); //K1---K16返回的键值分别为0---15
P2=0xff; //消隐
P0 = LedHexCode[ DisBuf[dots] ];
P2 =(1<<dots)^0xff;
if( ++dots >= 4 ){ dots=0; }
} //回到执行前面的while语句
}
/*下面是延时函数的描述*/
void delayMs( unsigned int tc ) //tc是形参
{
while( tc != 0 ) //如果tc为0则终止延时
{
unsigned int i; //局部正整数变量 i
for(i=0; i<400; i++); //执行400次将耗时1毫秒
tc--; //tc计数减一
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -