51单片机代码学习

void Timer0_Routine() interrupt 1
{
    TH0=64535/256;
    TL0=64535%256; //这两行就是让定时器的初值保持在一个值,这样就可以使得到达溢出的时间为1ms;
    T0Count++;  
    if(T0Count>=1000) //一秒钟的间隔才会作用
    {
        T0Count=0;// 将一秒钟间隔重新开始计数
      P2_0=~P2_0;
    }  
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
51计算器程序#include #include #define uchar unsigned char #define uint unsigned int sbit lcden=P3^4; sbit lcdrw=P3^6; sbit lcdrs=P3^5; uchar num,temp,jia=0,cheng=0,chu=0,jian=0,qing=0; uint key,key1,shu; uchar fuhao,flag1,flag=0; uchar table[]={ 0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x00,}; void delay(uint z) { uint x,y; for(x=z;x>0;x--) for(y=114;y>0;y--); } bit lcd_bz() { bit result; lcdrs = 0; lcdrw= 1; lcden = 1; _nop_(); _nop_(); _nop_(); _nop_(); result=(bit)(P0&0x80;); lcden=0; return result; } void write_com(uchar com) { while(lcd_bz()); lcdrs=0; lcden=0; lcdrw=0; P0=com; delay(5); lcden=1; delay(5); lcden=0; } void write_date(uchar date) { while(lcd_bz()); lcdrs=1; lcden=0; lcdrw=0; P0=date; delay(5); lcden=1; delay(5); lcden=0; } void lcd_init() { lcden=0; write_com(0x38); write_com(0x0c); write_com(0x06); write_com(0x01); } void keyscan() { P3=0xfe; temp=P3; temp=temp&0xf0; while(temp!=0xf0) { delay(5); temp=P3; temp=temp&0xf0; while(temp!=0xf0) { temp=P3; switch(temp) { case 0xee:key=1;num=0;break; case 0xde:key=2;num=0;break; case 0xbe:key=3;num=0;break; case 0x7e:num=1;break; //¼ÓºÅ } while(temp!=0xf0) { temp=P3; temp=temp&0xf0; } } } P3=0xfd; temp=P3; temp=temp&0xf0; while(temp!=0xf0) { delay(5); temp=P3; temp=temp&0xf0; while(temp!=0xf0) { temp=P3; switch(temp) { case 0xed:key=4;num=0;break; case 0xdd:key=5;num=0;break; case 0xbd:key=6;num=0;break; case 0x7d:num=2;break; //¼õºÅ } while( temp!=0xf0) { temp=P3; temp=temp&0xf0; } } } P3=0xfb; temp=P3; temp=temp&0xf0; while(temp!=0xf0) { delay(5); temp=P3; temp=temp&0xf0; while(temp!=0xf0) { temp=P3; switch(temp) { case 0xeb:key=7;num=0;break; case 0xdb:key=8;num=0;break; case 0xbb:key=9;num=0;break
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值