51单片机按键控制数码管?
#includesbit LED2 = p3 ^3 ; //接收AA,P.2 输出高水平,P3 .3 输出低水平。
sbit k0=P3 ^5 ;bit y0,t,s;uchar k;uchartable[]={0x3 f,0x06 ,0x5 b,0x4 f,0x6 6 ,0x6 d,0x7 d,0x07 ,0x7 f,0x6 f,0x3 f,0x06 ,0x5 b,0x4 f, 0x6 6 ,0x6 d,0x7 d}; voidsendonechar(charc)//将字节发送到PC {ti = 0; sbuf = c; 而(!ti); ti = 0; } voidsendstring(char*st)//将字符串发送到PC {while(*st){sendOneChar(*st ++); }} voidmain(void){scon = 0x5 0; // ren = 1 允许串行接受状态,串行端口工作模式1 tmod = 0x2 1 ; //计时器工作模式2 PCON = 0x8 0; //数据位8 ,停止位1 有效数字NO(1 1 .05 9 2 m)TH1 = 0xF4 ; // th1 = 0xfd; 波特率2 4 00 th0 =(6 5 5 3 6 -5 4 2 5 3 )/2 5 6 ; // 5 0ms TL0 =(6 5 5 3 6 -5 4 2 5 3 )%2 5 6 ; tr1 = 1 ; ES = 1 ; //打开串行端口中断ea = 1 ; //打开总中断LED1 = 1 ; LED2 = 0; // ET0 = 1 ; // TR0 = 1 ; s = 1 ; k = 0; p1 =〜表[k]; 而(1 ){if(k0 == 0 && y0 == 0){y0 = 1 ; c =“ az”; sendstring(c); //发送字符串} if(k0 == 1 ){y0 = 0;}}} voidchuankou(void)interrupt4 {if(ri == 1 ){ri = 0; if(t == 1 ){if(sbuf =='s'){LED1 = 〜LED1 ; LED2 = 〜LED2 ; K ++;} // if(SBUF =='S'){LED1 = 1 ; LED2 = 0 ; k--;} s = 1 ; t = 0; if(k == 1 0){k = 0;} if(k == 2 5 5 ){k = 9 ;} p1 =〜表[k]; } // 1 a No. 2 B-如果(sbuf =='a'&& s == 1 ){t = 1 ; s = 0;}}} voidt0_time()interrupt1 {th0 =(6 5 5 3 6 -5 4 2 5 3 ) /2 5 6 ; // 5 0ms TL0 =(6 5 5 3 6 -5 4 2 5 3 )%2 5 6 ; K ++; if(k == 1 0)//这里的修改时间{k = 0; LED1 = 1 ; LED2 = 1 ; }}}
真的很急!基于51单片机的DS18B20 温度测控系统 C语言程序
#includeif(flag_get == 1 )// //定期读取当前温度{temp = farts温度(); if(temp&0x8 000){str [0] = 0x4 0; //负符号temp =〜temp; //添加添加1 Temp+= 1 ;} elSestres [0] = 0; temph = temp >> 4 ; templ = temp&0x0f; Templ = Templ*6 /1 0; //十进制纠正处理flag_get = 0;}}}}}/*** ******************************************************************************************** ******************************** //*计时器 中断*/************************************************************************************************************************ ********** 温度检测间隔{th0 = 0xef; 5 0){num = 0;
flag_get = 1 ; //标志-bit有效
second ++;
if(第二> = 6 0)
{second = 0;
分钟++;
}} count ++; if(count == 1 ){p2 = 0;
dataLed = str [0];} //数字管扫描如果(count == 2 ){p2 = 1 ;
dataLed = str [1 ];} if(count == 3 ){p2 = 2 ; dataLed = str [2 ];} if(count == 4 ){p2 = 3 ; dataLed = str [3 ];} if(count == 5 ){p2 = 4 ; dataled = str [4 ];} if(count == 6 ){p2 = 5 ; ************* ******************************************************************************************************************* ******** //*延迟功能*// ********************************************************************************** *********************。
********************************************************************************************************************** ****************************************************************************************************************** **********/voidinit_ds1 8 b2 0(void){unsignedCharx = 0; dq = 1 ; // DQ重置延迟(8 ); //一点延迟dq = 0; //单芯片 - 之前的DQ-low延迟(8 0); //确切的延迟大于4 8 0USDQ = 1 ; //公共汽车延迟(1 0); x = dq; //稍作延迟后,如果x = 0,初始化成功,x = 1 ,。
初始化不会下降(5 ); ***** ********************************************************************************************************* ************************************************************************************************************************** *** ; //脉冲信号dat >> = 1 ; dq = 1 ; // pulsignal i f(dq)dat | = 0x8 0; 延迟(5 );}返回 (dat);}/**************************************************************************************************************** ******* ******************************************************************************************************************* ********* ******************************************************************************************************************* ****** **************************************************************************************************************** {unsignedChari = 0; for(i = 8 ; i> 0; i-){dq = 0; dq = dat&0x01 ; 延迟(5 ); dq = 1 ; dat >> = 1 ;}延迟(5 );}/ *************************************************************************************************************************************** ************ ******************************************************************************************************************************************************************************************************** *; //开始温度转换延迟(2 00); init_ds1 8 b2 0(); writeOnechar(0xcc); //跳过阅读过程的序列号' //读取温度寄存器等。
(总共可以读取9 个寄存器)。
前两个是温度a = readonechar(); //低位B = ReadOneChar(); //高-bit b
51单片机数码管显示的程序是什么?
#include // 5 2 系列microcontroller文件\ x0d \ x0a#deneChandEnsigned chare // macro deaction \ x0d \ x0a#defenetuntunsignedin \ x0d \ x0asbitdula = p2 ^6 ; 7 ; x0d \ x0aucarnum1 ,num2 ; \ x0d \ x0aucharcodetable [] = {// array dendiT \ x0d \ x0a 0x3 f,0x06 ,0x5 b,0x4 f,0x6 6 ,0x6 d,0x7 d,0x7 d,0x07 ,0x3 9 ,0x5 e,0x3 9 ,0x5 e,0x7 9 ,0x7 9 ,0x7 1 }; \ x0d \ x0auchar codeaable [] = {//位select select array \ x0d \ x0a 0xfe,0xfd,0xfb,0xfb,0xf7 ,0xef,0xdf}; \ x0d \ x0avoddilays(uint); \ x0d \ x0a {\ x0d \ x0a while(1 )\ x0d \ x0a {\ x0d \ x0a {\ x0d \ x0d \ x 0afor(num1 = 0; 0; 0; 0; \); \ x0d \ x0a} \ x0d \ x0a/*---------------------------------------------------------------------------------------- -------------------------------------------------------------------------- -------------------------------------------------------------------------- ------------------- ----------------------------------------------------------------------------- --------------------------------------------------------------------------- - ---------------------*/51单片机怎么用按键控制一个数码管,按一下显示一个数字,顺序显示
I.首先,用数字管中的光很好地编写代码。2 编写代码后,确认原始代码是否为真。
3 确认代码为真后,然后逐步删除这四个单词以将行代码(在箭头指向)的位置。
4 然后,如图所示,删除了四个单词,只需将它们更改为相应的代码编号。
V.在这里,我们更改代表数字0的代码,如形状所示。
6 最后写代码后,在微控制器中写入生成的十六进制文件,并在数字管拟合0中显示的数字。