| 
 
| 现在做成了硬件,但不知道怎么检测,写进去的程序在PROTUES 仿真能显示正常,但实物不行。。。:(,请大侠指点。 ************************************************************
 *************************************************************
 #include <reg51.h>
 #define uchar unsigned char
 #define uint unsigned int
 /*************位定义***********************/
 sbit ENABLE=P3^0;
 sbit EOC=P3^3;
 sbit START=P3^2;
 sbit CLK=P3^4;
 //sbit dot=P2^7;
 /*************赋值*************************/
 uint digtial[4],getdataend;
 uchar code dis[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,
 0x82,0xf8,0x80,0x90,0x88,0x83,
 0xc6,0xa1,0x86,0x8e};
 //uchar code dis[] = {0X3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F};
 uchar getdata;
 
 //*************************************************
 //函数名称:void delay1ms( unsigned char t)
 //函数功能:延时函数
 //返回类型:无
 //使用说明:
 //         1:产生需要的延时时间
 //*************************************************
 
 void delay1ms( unsigned char t)
 {
 unsigned char i,j;
 for( ; t; t--)
 for(i=4; i>0; i--)
 for(j=123; j>0; j--);
 }
 void time_time_clk() interrupt 1  using 0
 {
 TH0 = (65536-2)/256;//给高8位赋值
 TL0 = (65536-2)%256;//给低8位赋值
 CLK=~CLK;
 }
 //********************
 //函数名称:void inint()
 //函数功能:初始化定时器.ADC0809
 //********************
 void inint()
 {
 TMOD = 0x01;//选择工作模式 16位
 TH0 = (65536-2)/256;//给高8位赋值
 TL0 = (65536-2)%256;//给低8位赋值
 EA  = 1;//开总中断
 ET0 = 1;//启动定时器0;
 TR0 = 1;//开定时器0
 START=0;//给ADC0809赋初值
 ENABLE=0;
 }
 
 //****************************
 //函数名称:void display()
 //函数功能:动态扫描,数码管显示电压值
 //****************************
 void display()
 {
 
 P0 = 0X38;
 P2 = dis[digtial[3]];
 // delay1ms(3000);
 // dot = 1;
 delay1ms(100);
 // P2 = 0X00;
 /* P0 = 0X0d;
 P2 = dis[digtial[2]];
 delay1ms(1);
 P2 = 0X00;
 P0 = 0X0b;
 P2 = dis[digtial[1]];
 delay1ms(1);
 P2 = 0X00;
 P0 = 0X07;
 P2 = dis[digtial[0]];
 delay1ms(1);
 P2 = 0X00;
 */
 }
 //*****************************
 //函数名称:void AD()
 //函数功能:将模拟电压转换为数字
 //*****************************
 void AD()
 {
 getdata=0xf0;
 P0=0x38;
 START=0;
 ENABLE=0;
 START=1;
 START=0;//启动AD转换
 while(EOC==0)
 {
 }//判断转换是否结束
 ENABLE=1;//允许输出
 delay1ms(2);
 getdata=P1;//将转换得到的数据赋给getdata
 ENABLE=0;//关闭输出
 /*因为ADC0809的模拟输入电压范围为0~+5V*/
 getdataend = getdata*(5000/255);
 digtial[3] = getdataend/1000; //最高位数值
 digtial[2] = getdataend%1000/100;
 digtial[1] = getdataend%100/10;
 digtial[0] = getdataend%10;//最低位数值
 
 }
 /*void LF398()
 {
 
 }*/
 void main()
 {
 inint();//定时器和ADC0809的初始化
 while(1)
 {
 // P0=0X40;
 // NOP_();
 // P0=0;
 AD();//AD转换
 display();//数码管显示
 
 }
 }
 
 
 | 
 
×本帖子中包含更多资源您需要 登录 才可以下载或查看,没有账号?注册 
  |