首 页文档资料下载资料维修视频包年699元
请登录  |  免费注册
当前位置:精通维修下载 > 文档资料 > 家电技术 > 维修教程知识 > 单片机栏
16进制转换算成10进制程序
来源:本站整理  作者:佚名  2011-05-07 08:13:36



16进制转换算成10进制程序


 unsigned char d[10];    //用于显示的10位显示缓存

 //========================================================
     //16进制to10进制输出子程序:显示数据,起始位,结束位,有无小数点
 //========================================================
 void output(unsigned long dd,unsigned char s,unsigned char
 e,unsigned char dip) {
     unsigned long div;
     unsigned char tm[8],i,j;
     div=10000000;
     for (i=0;i<8;i++) {
         tm[i]=dd/div;
         dd%=div;
         div/=10;
     }
     for (i=0;i<6;i++) {
         if (tm[i]!=0) break;
         tm[i]=nul;
     }
     tm[5]|=dip;            //小数点控制,请看“串行LED数码管显示驱动程序”
     j=7;
     for (i=s;i<e;i++) {
         d[i]=tm[j];
         j--;
     }
 }

 //把显示位5-9位的10进制数转换成为16进制数
 unsigned int input(void) {
     unsigned int dd,dat;
     dd=10000;dat=0;
     for (i=5;i<10;i++) {
         dat+=dd*temp;
         dd/=10;
     }
     return(dat);
 }
 /*    89C51系列CPU编程器接收CPU程序*/

 #i nclude <reg51.h>
 #i nclude <intrins.h>
 #i nclude <absacc.h>

 #define e 8
 #define p 9
 #define l 10

 sbit led=P3^2;
 sbit p27=P2^7;
 sbit p26=P2^6;
 sbit p36=P3^6;
 sbit p37=P3^7;
 sbit rst=P3^3;
 sbit ale=P3^5;
 sbit vpp=P3^4;

 bit b_break;
 unsigned int adds;


 //    13.8mS
 void int_t0(void) interrupt 1 {
     TH0=-100;
     b_break=1;
 }

 void wait(unsigned char w) {
     unsigned int t=w*184;
     b_break=0;
     TL0=-t%256-1;TH0=-t/256;
     while (b_break==0) {}
 }

 void nop(void) {
     _nop_();_nop_();_nop_();_nop_();
     _nop_();_nop_();_nop_();_nop_();
     _nop_();_nop_();_nop_();_nop_();
     _nop_();_nop_();_nop_();_nop_();
     _nop_();_nop_();_nop_();_nop_();
 }

 unsigned char command(void) {
     TH0=-100;b_break=0;
     while (RI==0) {if (b_break==1) return(0);}
     RI=0;
     return(SBUF);
 }

 void earsure(unsigned char cpu) {
     switch (cpu) {
     case 1:        //89C51
     case 2:rst=p26=1;p27=p36=p37=0;nop();vpp=1;nop();
         ale=0;wait(110);ale=1;nop();
         break;
     case 3:
     case 4:break;
     case 5:
     case 6:break;
     }
 }

 void program(unsigned char cpu) {
     unsigned int bdata adds=0;
     unsigned char d;
     switch (cpu) {
     case 1:    //89C51
     case 2:
         p36=p37=1;rst=1;
         while (1) {
             TH0=-100;b_break=0;
             while (RI==0) {if (b_break==1) return;}
             RI=0;
             d=SBUF;
             //address
             P0=adds%256;
             P2=adds/256;
             p27=1;
             //data
             P1=d;
             nop();    //48clcl
             //vpp
             vpp=1;
             nop();    //48clcl
             //ale
             ale=0;
             wait(1);//100uS
             ale=1;
             nop();    //10uS
             vpp=0;
             nop();    //48clcl
             p27=0;
             nop();    //48clcl
             P1=0xff;
             TH0=-100;b_break=0;
             while (d!=P1) {if (b_break==1) return;}    //data
polling
             SBUF=d;
             adds++;
         }
         break;
     case 3:
     case 4:
     case 5:
     case 6:break;
     }
 }

 void lock(unsigned char cpu) {
     unsigned char i;
     switch (cpu) {
     case 1:    //89c51
     case 2:
         //lock 1
         rst=p26=p36=p27=p37=1;nop();
         vpp=1;
         nop();
         ale=0;
     //    for (i=0;i<6;i++) wait(100);
         wait(1);
         ale=1;
         nop();
         vpp=0;
         nop();
    
         //lock 2
         rst=p26=p27=1;p36=p37=0;nop();
         vpp=1;
         nop();
         ale=0;
     //    for (i=0;i<6;i++) wait(100);
         wait(1);
         ale=1;
         nop();
         vpp=0;
         nop();
        
         //lock 3
         rst=p26=p36=1;p27=p37=0;nop();
         vpp=1;
         nop();
         ale=0;
     //    for (i=0;i<6;i++) wait(100);
         wait(1);
         ale=1;
         nop();
         vpp=0;
         nop();
         break;
     case 3:
     case 4:
     case 5:
     case 6:break;
     }
 }

 void main(void) {
     unsigned char disp,flash,temp,cpu;
     EA=1;
     SCON=0xd8;PCON=0x80;
     TMOD=0x21;
     TL1=TH1=0xff;TR1=1;
     TH0=-100;ET0=TR0=1;

     flash=0x80;

关键词:

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分)
Copyright © 2007-2017 down.gzweix.Com. All Rights Reserved .
页面执行时间:61,093.75000 毫秒