格美乐插卡双人跳舞毯插电视上显示无信号 AV和各频道都显示无信号。电视是东芝液晶的

STC12C5A60S2 AD转换C语言程序,转换结果在1602液晶上显示。

2011-08-18 10:01QBJ2011Q | 分类:C/C++ | 浏览6168次

分享到:

2011-08-18 11:43 提问者采纳

//1602 四线制驱动程序,根据需要自己改端口定义和延时

#define LINE1 0

#define LINE2 1

#define LINE1_HEAD 0x80

#define LINE2_HEAD 0xC0

#define CLEARSCREEN LCD_en_com(0x01);LCD_delay(30)

/*************************************/

//change this part at different board

sbit DB7=P2^7;

sbit DB6=P2^6;

sbit DB5=P2^5;

sbit DB4=P2^4;

sbit LCD1602_RS=P2^1; //data command select 1 data 0 command pin 4

sbit LCD1602_RW=P2^2; //read write select 1 read 0 write pin 5

sbit LCD1602_EN=P2^3; //LCD enable signal pin 6

/********************************************************************/

void LCD_delay(unsigned int n)

{

unsigned int i=0,j=0;

for (i=n;i>0;i--)

for (j=0;j<12;j++);

}

void LCD_en_com(unsigned char command)

{

DB7=(command>>7)%2;

DB6=(command>>6)%2;

DB5=(command>>5)%2;

DB4=(command>>4)%2;

LCD1602_RS = 0; //RS 0

LCD1602_RW = 0; //RW 0

LCD1602_EN = 1; //EN --\|/__ Write command

LCD_delay(2);

LCD1602_EN = 0;

DB7=(command>>3)%2;

DB6=(command>>2)%2;

DB5=(command>>1)%2;

DB4=(command>>0)%2;

LCD1602_RS = 0; //RS 0

LCD1602_RW = 0; //RW 0

LCD1602_EN = 1; //EN --\|/__ Write command

LCD_delay(2);

LCD1602_EN = 0;

}

void LCD_en_dat(unsigned char command)

{

DB7=(command>>7)%2;

DB6=(command>>6)%2;

DB5=(command>>5)%2;

DB4=(command>>4)%2;

LCD1602_RS = 1; //RS 1

LCD1602_RW = 0; //RW 0

LCD1602_EN = 1; //EN --\|/__ Write data

LCD_delay(2);

LCD1602_EN = 0;

DB7=(command>>3)%2;

DB6=(command>>2)%2;

DB5=(command>>1)%2;

DB4=(command>>0)%2;

LCD1602_RS = 1; //RS 1

LCD1602_RW = 0; //RW 0

LCD1602_EN = 1; //EN --\|/__ Write data

LCD_delay(2);

LCD1602_EN = 0;

}

void LCD_set_xy(unsigned char x,unsigned char y)

{

unsigned char address;

if(y == LINE1)

address = LINE1_HEAD + x;

else

address = LINE2_HEAD + x;

LCD_delay(10);

LCD_en_com(address);

}

void LCD_write_string(unsigned char x,unsigned char y,unsigned char *s)

{

LCD_set_xy(x,y);

while(*s)

{

LCD_en_dat(*s);

s++;

}

}

/********************************************************************/

void InitTimer0(void)//200us

{

TMOD = 0x01;

TH0 = 0x0FE;

TL0 = 0x70;

EA = 1;

ET0 = 1;

TR0 = 1;

}

unsigned char LCD_ContCount=0;

sbit LCDCONT=P2^0;

void Timer0Interrupt(void) interrupt 1

{

TH0 = 0x0FE;

TL0 = 0x70;

if(LCD_ContCount<LCD_CONTRAST){LCDCONT=0;}

else{LCDCONT=1;}

LCD_ContCount++;

if(LCD_ContCount==100){LCD_ContCount=0;}

}

/********************************************************************/

void LCD_init(void)

{

LCD_delay(50);

LCD_en_com(0x33);//原来1602初始化成4位数据线之前必需先初始化成8位(此时命令发送方式是8位格式,但数据线只需接4位)

LCD_delay(10);

LCD_en_com(0x32);//然后再改到4位线宽,这样初始化才稳定

LCD_delay(10);

LCD_en_com(0x28);//四线模式设置

LCD_delay(10);

LCD_en_com(0x0c);//显示开--对应开关显示控制指令

LCD_delay(10);

CLEARSCREEN;

InitTimer0();

}

/********************************************************************/

至于AD,用片上自带的AD就行,没有具体的电路,只能帮你这些了。

另:楼上说用ADC0834的,STC12C5A60S2已经有AD了啊