原创 DAC0804 C程序

2010-6-11 08:45 1933 1 1 分类: MCU/ 嵌入式
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit cs="P3"^3;
sbit rd="P3"^4;
sbit wr="P3"^5;
uchar tab[]={0xc0,0xf9,0xa4,0xb0,
 0x99,0x92,0x82,0xf8,0x80,0x90};
uchar disp[5]={0,0,0,0,0};
uint results;
void delay(uint t)
{
 uchar i;
 while(t--)
 for(i=0;i<125;i++);
}
void display()
{
 uchar j,scan;
 int i="80";
 while(--i>=0)
 {
  scan=4;
  for(j=0;j<5;j++)
  {
   P0=0xff;
   P2=~scan;
   P0=tab[disp[j]];
   if(j==4)
   P0=tab[disp[j]]&0x7f;
   delay(3);
   scan<<=1;
  }
 }
}
void transfer()
{
 cs=1;
 wr=1;
 rd=1;
 P1=0xff;
 cs=0;
 wr=0;
 _nop_();
 wr=1;
 cs=1;
 display();
 cs=0;
 rd=0;
 results=P1*196;
 _nop_();
 rd=1;
 cs=1;
}
void main()
{
 while(1)
 {
  transfer();
  disp[4]=results/10000;
  disp[3]=(results/1000)%10;
  disp[2]=(results/100)%10;
  disp[1]=(results/10)%10;
  disp[0]=results%10;
 }
}
PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
我要评论
0
1
关闭 站长推荐上一条 /4 下一条