標(biāo)題: 求程序補(bǔ)充和修改。!謝謝了 [打印本頁(yè)]

作者: 電子大白菜    時(shí)間: 2012-4-1 19:23
標(biāo)題: 求程序補(bǔ)充和修改!!謝謝了

將從外部輸入IO口的數(shù)據(jù)轉(zhuǎn)為10進(jìn)制數(shù),顯示在數(shù)碼管上

 

我不知道怎樣將IO口的數(shù)據(jù)讀入

求各位大俠幫小弟看看后面改怎么寫,怎么改

謝謝各位大俠!!

 

 

#include<reg52.h>
#include<string.h>
#define uchar unsigned char
#define uint unsigned int
sbit a1=P3^0;
sbit a2=P3^1;
sbit a3=P3^2;
sbit a4=P3^3;
sbit a5=P3^4;
sbit a6=P3^5;
sbit a7=P3^6;
sbit a8=P3^7;
sbit a9=P0^0;
sbit a10=P0^1;
sbit a11=P0^2;
sbit a12=P0^3;
sbit a13=P0^4;
sbit a14=P0^5;
uchar code tabledu[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x40,0x80,0x00};
uchar count,wang,qin,bai,shi,ge;
uint temp,aa,n,j,i,t=0,p=1;
char a[50];
//延遲函數(shù)
void delay(uint z)
{
 uint x,y;
 for(x=z;x>0;x--)
  for(y=110;y>0;y--);
}
//初始化函數(shù)
void init()
{
 TMOD=0x01;              //定時(shí)器T0為工作方式1
 TH0=(65536-50000)/256;
 TL0=(65536-50000)%256;
 ET0=1;
 EA=1;     //開啟總中斷
 TR0=1;     //啟動(dòng)定時(shí)器
 count=0;

}
//顯示函數(shù)
void display(uchar wang,uchar qin,uchar bai,uchar shi,uchar ge){
  
  P2=tabledu[wang];
  P1=0x00;
  delay(1);

  P2=tabledu[qin];
  P1=0x01;
  delay(1);

  P2=tabledu[bai];
  P1=0x02;
  delay(1); 

  P2=tabledu[shi];
  P1=0x03;
  delay(1); 

  P2=tabledu[ge];
  P1=0x04;
  delay(1);
 

}
void main()
{
 init();
 char a[50];             //將2進(jìn)制數(shù)轉(zhuǎn)為10進(jìn)制數(shù)
 gets(a);
 n=strlen(a);
 for(i=n-1;i>=0;i--)
 {
    p=1;
    t=(a-48);
    if(i==n-1)
    {
     p=1;
    }
    else
    {
     for(j=0;j<n-i-1;j++)
     {
           p=p*2;
     }
    }
    temp+=t*p;
 }
    、
    while(1){
  if(count==10){
   count=0;
   wang=temp/10000;
   qin=temp%10000/1000;
      bai=temp%10000%1000/100;
            shi=temp%10000%1000%100/10;
         ge=temp%10;
  
  }
 
  display(wang,qin,bai,shi,ge); //調(diào)用顯示函數(shù)
 }
}
void timer0() interrupt 1
{
 TH0=(65536-50000)/256;
 TL0=(65536-50000)%256;
 count++;
}


作者: 電子大白菜    時(shí)間: 2012-4-5 13:03

各位大俠。兔纯茨

謝謝各位大俠了。。!






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1