專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計(jì)實(shí)例 >> 瀏覽文章

11路AD轉(zhuǎn)換TLC2543CN c程序

作者:佚名   來(lái)源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2011年09月19日   【字體:

采用1602液晶來(lái)顯示轉(zhuǎn)換結(jié)果,端口可以很方便的自己修改的

#include <reg51.h>
#include <intrins.h>
#include <stdlib.h> 
#define uchar unsigned char
#define uint  unsigned int
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar vol[3]={000},channel[11]={0x0c,0x1c,0x2c,0x3c,0x4c,0x5c,0x6c,0x7c,0x8c,0x9c,0xac};
/* 端口定義*/
#define LCD_data  P0             //數(shù)據(jù)口
sbit inter_0=P3^2;
sbit LCD_RS  =  P2^7;            //寄存器選擇輸入
sbit LCD_RW  =  P2^6;            //液晶讀/寫(xiě)控制
sbit LCD_EN  =  P2^5;            //液晶使能控制
sbit LCD_PSB =  P2^4;            //串/并方式控制
sbit eoc=P1^0;
sbit clock=P1^1;
sbit in=P1^2;
sbit out=P1^3;
sbit cs=P1^4;
uint din;
void delay(uint x)
{
uint i,j;
for(j=0;j<x;j++) 
 for(i=0;i<110;i++);
}  
/*******************************************************************/
/*                                                                 */
/*寫(xiě)指令數(shù)據(jù)到LCD                                                  */
/*RS=L,RW=L,E=高脈沖,D0-D7=指令碼。                             */
/*                                                                 */
/*******************************************************************/

 

 


void write_cmd(uchar cmd)
{                         
    LCD_RS = 0;
    LCD_RW = 0;
    LCD_EN = 0;
    P0 = cmd;
 delay(5);
    LCD_EN = 1;
 delay(5);
    LCD_EN = 0; 
}
/*******************************************************************/
/*                                                                 */
/*寫(xiě)顯示數(shù)據(jù)到LCD                                                  */
/*RS=H,RW=L,E=高脈沖,D0-D7=數(shù)據(jù)。                               */
/*                                                                 */
/*******************************************************************/
void write_dat(uchar dat)
{                         
    LCD_RS = 1;
    LCD_RW = 0;
    LCD_EN = 0;
    P0 = dat;
 delay(5);
    LCD_EN = 1;
 delay(5);
    LCD_EN = 0; 
}
/*********************************************************/
/*                                                       */
/* 設(shè)定顯示位置                                          */
/*                                                       */
/*********************************************************/
void lcd_pos(uchar X,uchar Y)
{                         
   uchar  pos;
   if (X==0)
     {X=0x80;}
   else if (X==1)
     {X=0x90;}
   else if (X==2)
     {X=0x88;}
   else if (X==3)
     {X=0x98;}
   pos = X+Y ; 
   write_cmd(pos);     //顯示地址
}

/*******************************************************************/
/*                                                                 */
/*  LCD初始化設(shè)定                                                  */
/*                                                                 */
/*******************************************************************/
void lcd_init()
{
    LCD_PSB = 1;         //并口方式 
    write_cmd(0x30);      //基本指令操作
    delay(5);
    write_cmd(0x0C);      //顯示開(kāi),關(guān)光標(biāo)
    delay(5);
    write_cmd(0x01);      //清除LCD的顯示內(nèi)容
    delay(5);
}
/*********************************************************/
/*               */
/* 主程序                     */
/*                                                       */
/*********************************************************/
main()
{ uchar i,k;
  uint num1[5];
  float num;
  uchar dout;
  delay(10);                 //延時(shí)
   lcd_init();

while(1)
{k=0;
while(k<11)
{din=0;

dout=channel[k];
while(eoc==0);
clock=0;cs=0;
for(i=0;i<16;i++)
{cs=0;
 if(dout&0x80)in=1;
 else         in=0;
 clock=1;
 dout<<=1;
 din<<=1;
 if(out==1)
 din|=0x0001;
 clock=0;
}
cs=1;
din>>=4;
 

 num=din/4096.0*5.0;
 num1[0]=(uint)(num)%10+48;
 num1[1]=46;
 num1[2]=((uint)(num*10))%10+48;
 num1[3]=((uint)(num*100))%10+48;
 lcd_pos(k/3,k%3*3);
 delay(5);
 write_dat(num1[0]);
 delay(5);
 write_dat(num1[1]);
 delay(5);
 write_dat(num1[2]);
 delay(5);
 write_dat(num1[3]);
 delay(5);
 k++;
}
 }
 
}
/*************************************/
關(guān)閉窗口

相關(guān)文章