1、创建一个新工程并选择使用51单片机 2、新建文本编辑c语言程序
3、将.c文件放入工程source group 1中并进行编译 编译成功 4、点击如图勾选create hex file生成hex文件才可以烧录到单片机中
创建成功
1、在proteus中新建一个工程 2、挑选器件绘制电路图,K1 K2两个开关可以调节时间的分钟与小时,到设定时间就会打铃。
1、点击仿真图中的51单片机,添加hex文件 2、点击运行仿真 仿真结果成功,初始设置值为星期一8:44:55 ,到达指定时间响铃。
1、新建一个新工程,选择STM32单片机,勾选如图 2、编译一个源程序 3、编译结果
本次学习只是嵌入式开发的入门级学习,由于以前对proteus和51单片机有一定的掌握,很快就对他们的使用熟悉起来,但是更加深入的了解与掌握还需要我们更刻苦的学习。 同时附上本次学习的源代码,其中涉及很多单片机的知识,希望对你有所帮助。
#include<reg51.h> #define uchar unsigned char sbit b1=P2^0; //数码管位选择端口 sbit b2=P2^1; sbit b3=P2^2; sbit b4=P2^3; sbit b5=P2^4; sbit b6=P2^5; sbit b7=P2^6; sbit b8=P2^7; sbit beep=P1^0; sbit k1=P1^2; sbit k2=P1^5; sbit d1=P1^7; unsigned char s=0,m,h,day; unsigned char f=0; //中断次数 unsigned char code a[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x27,0x7f,0x6f}; void chushi(void) { TMOD=0x01; //置定时计数器为方式一 TH0=(65536-50000)/256; TL0=(65536-50000)%256; //计数初值 ET0=1;//启用T0; EA=1; TR0=1; //T0工作 } /*void change() { if(k1==0) { EA=0; m++; } if(k2==0) { h++; } EA=1; } */ void time(void) interrupt 1 //T0溢出中断 { TH0=(65536-50000)/256; TL0=(65536-50000)%256; f++; if(f==20) //每中断20次,计数1秒后 { f=0; s++; //秒+1 if(k1==0) s=60; if(k2==0) { h++; if(h>23) { h=0; day++; } } if(h>23) h=0; if(s>59) { s=0; m++; } if(m>59) { m=0; h++; } if(h>23) { h=0; day++; } if(day>7) { day=0; } } } void ys(char x) //延时 { char hk; for(x;x>0;x--) { for(hk=200;hk>0;hk--) {} } } void display() //数码管显示 { uchar s1,s2,m1,m2,h1,h2,day1; //秒分时的十位与个位 s1=s/10;s2=s%10;m1=m/10;m2=m%10;h1=h/10;h2=h%10;day1=day%10; P0=a[s1];b7=0;ys(10);b7=1; P0=a[s2];b8=0;ys(10);b8=1; P0=0x40;b6=0; ys(10);b6=1; P0=a[m1];b4=0;ys(10);b4=1; P0=a[m2];b5=0;ys(10);b5=1; P0=0x40;b3=0;ys(10);b3=1; P0=a[h1];b1=0;ys(10);b1=1; P0=a[h2];b2=0;ys(10);b2=1; P3=a[day1]; if(day==1&&day<6) //排除星期六星期天 { if(h==8&&m==0&&m<1) {beep=0;}//延时一分钟 //八点叫 if(h==8&&m==45&&m<46) {beep=0;} if(h==8&&m==55&&m<56) {beep=0;} if(h==9&&m==40&&m<41) {beep=0;} if(h==10&&m==10&&m<11) {beep=0;} if(h==10&&m==55&&m<56) {beep=0;} if(h==11&&m==5&&m<6) {beep=0;} if(h==11&&m==50&&m<51) {beep=0;} if(h==14&&m==0&&m<1) {beep=0;} if(h==14&&m==40&&m<41) {beep=0;} if(h==14&&m==55&&m<56) {beep=0;} if(h==15&&m==40&&m<41) {beep=0;} if(h==16&&m==10&&m<11) {beep=0;} if(h==16&&m==55&&m<56) {beep=0;} if(h==17&&m==5&&m<6) {beep=0;} if(h==17&&m==50&&m<51) {beep=0;} } beep=1; } void main() { m=44; h=8; s=55; day=1; //设置时间星期一8:44:55 chushi(); while(1) { display(); } }