First on the code: #include <reg52.h> #define uchar unsigned char #define uint unsigned int sbit SegSel=P2^6; //Segment selection sbit BitSel=P2^7;
Category: c51
51 MCU buzzer operation
It is very simple to make the buzzer sound. Add a low level to the buzzer so that the current
Microcontroller shift operation; use of _crol_ and _cror_
Let the first small light flash sequentially to the last one, you can use shift to achieve the purpose. The
Detecting target MCU…
Detecting target MCU… The microcontroller is not easy to burn out. Solution: Connect P1.0 and P1.1 to GND with DuPont
51单片机定时控制灯
让第一个小灯亮0.5秒,再熄灭0.5秒。 我们先随便写一个小灯闪烁的程序,以第一个小灯为例。 #include <reg52.h> sbit L1=P1^0; void main() { int a; while(1) { a=66666; L1=0; while(a–); a=66666; L1=1; while(a–); }
单片机定时功能的实现
单片机定时功能 先上代码,然后再解释: <span style=”font-family:System;”>//定時器功能 void timer_0(void) { TMOD=0x01; //採用定時器T0,工作方式為1(16位定时器) IE=0x82; //二進制1000|0010,七位為1表示全局中斷打開,即EA=1,一位為1表示定时器0中斷打開 TH0=0xD8; //定時器高八位賦值65536 TL0=0xEF; //定时器第八位赋值55536 //65536-55536=10000,因此12M晶振单片机中:計數10000個機器週期使用10ms } //定時器T0中斷函數 void Timer0(void)
51单片机点亮数码管
点亮数码管,例如使第一个数码管显示1。 首先,我们需要点亮第一个数码管,则电位为1111,1110,转换为十六进制为0xfe。 然后,让第一个数码管显示1,1对应的十六进制为0x06. 代码如下: #include <reg52.h> sbit dula=P2^6; //段选 sbit wela=P2^7; //位选 void main() { wela=1; P0=0xfe;//第一个数码管亮 wela=0; dula=1; P0=0x06;
51单片机蜂鸣器操作
让蜂鸣器响很简单,给蜂鸣器加一个低电平,这样电流通过,蜂鸣器就会响。 代码很简单,应该很容易懂的! #include <reg52.h> sbit beep=P2^3; void main() { int a; while(1) { a=66666; beep=0; while(a–); a=66666; beep=1; while(a–); }
数码管动态显示123456
先上代码: #include <reg52.h> #define uchar unsigned char #define uint unsigned int sbit SegSel=P2^6; //段选 sbit BitSel=P2^7; //位选 unsigned char code
单片机移位操作;_crol_ 和_cror_ 的使用
让第一个小灯到最后一个依次闪烁,可以用移位来达到目的。 单片机有一个库文件已经写好了移位函数,储存在#include <intrins.h>库文件里。 1 _crol_字符循环左移 字符循环左移: #include <reg52.h> #include <intrins.h> char tmp; void delay() //延时函数 { int i; for(i=0;i<8888;i++) ;
正在检测目标单片机…
单片机不容易烧坏。 解决方法:用杜邦线把 P1.0 口和 P1.1 口接GND,即接地。之后下载程序。 原因:单片机锁了,所以下载不进程序了。 其他情况: 1.查看单片机是否插反了; 2.下载软件选择正确的单片机型号(注意STC89C52和STC89C52RC是不同的) ; 3.检测是否连接了晶振 ,时候有晶振接触不良的现象 ; 4.查看电脑com是否有多个,是否选错了com口 (是否安装了相应的驱动); 5.单片机开发板是否重新上电了(下载单片机程序需要冷启动过程) ; 6.注意是否有短路(比如开发板下面最好铺一张纸,不要被短路) ;