#define uchar unsigned char
#define uint unsigned int
#define lcd_ports P1
sbit lcdrs=P3^5
sbit lcdrw=P3^3
sbit lcde=P3^4
void delay(uint z) //延迟子程序
{
uchar i,j
for(i=zi>0i--)
for(j=256j>0j--)
}
void write_com(uchar com) //1602写指令
{
lcdrs=0
P1=com
delay(5)
lcde=1
delay(5)
lcde=0
}
void write_data(uchar date) //1602写数据,写的是你要显示数据的ASCLL码值
{
lcdrs=1
P1=date
delay(5)
lcde=1
delay(5)
lcde=0
}
void init() //初始化
{
lcdrw=0
lcde=0
write_com(0x38)//使液晶显示点阵
write_com(0x0e)//初始设置
write_com(0x06) //初始设置
write_com(0x01) //清零
write_com(0x80+0x00)//使指针指向第一行第一列
}
void main()
{
init()
while(1){
write_com(0x80)//从第一行第一列开始写数据。
write_data(0x73) //显示s字符
write_data(0x69)//第一行第二列显示字符i
write_data(0x6e)//第一行第三列显示字符n
write_data(0x65)//第一行第四列显示字符e;}
}
无语了:
生僻单词:长这么大,第一次见到:initialise,一查,结果还真有这个单词:vt. (英)初始化;赋初值;预置(等于initialize)
错误写法:
LCD_commond_tx(ox40)一看就是错误的,应该是:LCD_command_tx,加上参数的0x40,而不是字母o加上x40。
另外,对于正确的:
LCD_command_tx
google一搜,就搜到了示例代码,供你参考:
void SPI_MasterInit(void){
// Set MOSI, SCK and SS port of uC as output and MISO as input
// (it sets SS high to make sure uC operates as Master)
SCK_DIR(OUT)
MOSI_DIR(OUT)
MISO_DIR(IN)
// Enable SPI, Master, set clock rate fck/16
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0)
}
void LCD_command_tx(byte cData)
{
// Start transmission
SPDR = cData
// Wait for transmission complete
while (!(SPSR & (1<<SPIF))) {
}
}
byte LCD_initialise(void)
{
LCD_CS(LOW) // Chip Select of LCD set to low
LCD_CS_DIR(OUT)
LCD_CD_DIR(OUT)
LCD_CD(COMMAND) // LCD put into command (LOW) mode
LCD_RST_DIR(OUT)
LCD_RST(HIGH)
_delay_ms(10)
LCD_RST(LOW) // RESET routine for the LCD
_delay_ms(5)
LCD_RST(HIGH)
_delay_ms(10)
LCD_command_tx(0x40) //Display start line 0
LCD_command_tx(0xA1) //SEG reverse
LCD_command_tx(0xC0) //Normal COM0~COM63
LCD_command_tx(0xA4) //Disable -> Set All Pixel to ON
LCD_command_tx(0xA6) //Display inverse off
_delay_ms(120)
LCD_command_tx(0xA2) //Set LCD Bias Ratio A2/A3
LCD_command_tx(0x2F) //Set Power Control 28...2F
LCD_command_tx(0x27) //Set VLCD Resistor Ratio 20...27
LCD_command_tx(0x81) //Set Electronic Volume
LCD_command_tx(0x10) //Set Electronic Volume 00...3F
LCD_command_tx(0xFA) //Set Adv. Program Control
LCD_command_tx(0x90) //Set Adv. Program Control x00100yz yz column wrap x Temp Comp
LCD_command_tx(0xAF) //Display on
return (TRUE)
}
int main(void)
{
MU_SS(HIGH) // Setting uC as a Master
MU_SS_DIR(OUT)
SPI_MasterInit()
LCD_initialise()
while (TRUE) //Master loop always true so always loop
{
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)