原创 adc0809和12864的简单显示

2008-5-21 20:26 1948 0 分类: MCU/ 嵌入式

/*-----本程序利用adc0809和12864来显示电压值到五伏-----*/
#include <REG52.H>
#include <absacc.h>
#define uchar unsigned char
#define uint unsigned int
sbit RST = P1^4;
sbit E   = P2^6;
uint ad_result;
#define ad_adr XBYTE[0x7fff] //宏定义
void delay(uint b)
{
 while(b--);
}
adc0809()
{
 uchar xdata *ad_res;
 ad_res=&ad_adr;
 *ad_res=2;
 delay(100);
 ad_result=*ad_res;
}


 


void write_com(uchar com)    //写命令到LCD 0000  RST    E    RW     RS     // 1    1 


   0    0
{
 delay(70);
 P2 = 0xCF;
 RST= 1;
 P0 = com;
 E  =0;            


 
}
void write_data(uchar dat)  //写数据到LCD   0000 // 1    1      0   1
{
 delay(70);
 P2 = 0xDF;
 RST=1;
 P0 = dat;
 E  = 0;
}
void chushihua(void)
{
   write_com(0x30); //8BitMCU,基本指令集合
   write_com(0x03); //AC归0,不改变DDRAM内容
   write_com(0x0c); //显示ON,游标OFF,游标位反白OFF
   write_com(0x01); //清屏,AC归0
}
 main()
 {
  
   chushihua();
  do
  {
     adc0809();
    write_com(0x80);
     
 write_data(ad_result*196/10000+48);          //显示最高位
 write_data(46);                              //显示小数点
 write_data(ad_result*196%10000/1000+48);     //显示次高位
 write_data(ad_result*196%1000/100+48);       //显示最底位
 delay(50000);
   }
    while(1);
 }


 


 


/*-----本程序利用adc0809和12864来显示电压值到十伏-----*/
#include <REG52.H>
#include <absacc.h>
#define uchar unsigned char
#define uint unsigned int
sbit RST = P1^4;
sbit E   = P2^6;
uint ad_result;
#define ad_adr XBYTE[0x7fff]  //宏定义
void delay(uint b)
{
 while(b--);
}
adc0809()
{
 uchar xdata *ad_res;
 ad_res=&ad_adr;
 *ad_res=2;
 delay(100);
 ad_result=*ad_res;
}


 


void write_com(uchar com)    //写命令到LCD 0000  RST    E    RW     RS     // 1    1 


   0    0
{
 delay(70);
 P2 = 0xCF;
 RST= 1;
 P0 = com;
 E  =0;            


 
}
void write_data(uchar dat)  //写数据到LCD   0000 // 1    1      0   1
{
 delay(70);
 P2 = 0xDF;
 RST=1;
 P0 = dat;
 E  = 0;
}
void chushihua(void)
{
   write_com(0x30); //8BitMCU,基本指令集合
   write_com(0x03); //AC归0,不改变DDRAM内容
   write_com(0x0c); //显示ON,游标OFF,游标位反白OFF
   write_com(0x01); //清屏,AC归0
}
 main()
 {
  
   chushihua();
  do
  {
     adc0809();
    write_com(0x80);
     
 write_data(ad_result*39/1000+48);           //显示最高位
 write_data(46);                             //显示小数点
 write_data(ad_result*39%1000/100+48);       //显示次高位
 write_data(ad_result*39%100/10+48);         //显示最底位
 delay(50000);
   }
    while(1);
 }


 

PARTNER CONTENT

文章评论0条评论)

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