① 单片机c51考试基础部分:要求用两个数码管动态显示两位十进制数00~59,数据 约1S加一; 求程序
#include<reg52.h>#define Port P0sbit seg1 = P2^0;
sbit seg2 = P2^1;unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66, <br> 0x6d,0x7d,0x07,0x7f, 0x6f};//共阴极数码管
unsigned char time1,time2,time;
unsigned char count;
bit flag;void Timer0_Init(){
TMOD=0x01;
TH0=(256*256-5000)/256;
TL0=(256*256-5000)%256;
ET0=1;
TR0=1;
EA=1;
}void main()
{
Timer0_Init();
seg1=1;
seg2=1;
while(1)
{
time1 = time / 10;
time2 = time % 10;
}
}void timer0(void) interrupt 1
{
TH0=(256*256-5000)/256;
TL0=(256*256-5000)%256;
flag=~flag;
count++;
if(count==200)
{
count = 0;
time++;
if(time == 60)
time = 0;
}
if(flag==1)
{
Port = table[time2];
seg1 = 0;
seg2 = 1;
}
else
{
Port = table[time1];
seg1 = 1;
seg2 = 0;
}
}
② 求解!有关c51单片机的填空题,有谁会啊
(1)c51单片机的中断控制寄存器为( IE )该寄存器各位对应相应的中断
源为( EA,ET2,ES,ET1,EX1,ET0,EX0 )TCON的定义是( 定时器、计数器控制寄存器 )
(2)c51单片机的定时/计数器的2个控制寄存器分别为( T0 )和( T1 ),其对应的
单片机引脚分别为( P3.4 )和( P3.5 )
(3)当c51单片机采用12MHZ晶体时,每个周期为( 1us )使用定时器T0定时10毫秒,定时器的初始值分别为( F0 )和( D8 )定时器的T0的控制位为( TR0=1 )
③ 【高分,在线等】单片机C51程序编程,初学的简单题目
#include<reg51.h>
void main(void)
{
unsigned char shuzhu[5]={1,2,1,3,5}; //随便设的数
unsigned char i,j,t;
for(j=0;j<4;j++)
for(i=0;i<=4-j;i++)
if(shuzhu[i]>shuzhu[i+1])
{
t=shuzhu[i];shuzhu[i]=shuzhu[i+1];shuzhu[i+1]=t;
}
}
用冒泡法就行了
④ 单片机C51程序编程题
#include
#define uchar unsigned char
#define uint unsigned int
sbit LED = P1^0;
uchar T_Count = 0;
void main()
{
TMOD = 0x01;
TH0 = (65535-5000)/256;
TL0 = (65535-5000)%256;
IE = 0x82;
TR0 = 1;
while(1);
}
void LED_Flash() interrupt 1
{
TH0 = (65535-5000)/256;
TL0 = (65535-5000)%256;
if(++T_Count == 100)
{
LED = !LED;
T_Count = 0;
}
}
⑤ 请问C51单片机的这道选择题怎么做
1)要对外部信号电平持续时间进行计数,就需要到内部计数脉冲信号,所以 C/T=0;
2)要用外部信号来启动定时/计数器,就要令 GATE=1;
3)因此从给出的选项看,只有 80 和 09 符号要求;
80 是启动 定时器1,方式0,13位计时计数器 (8192)
09 是启动定时器0;方式1,16位计时计数器 (65536)