高级会员
- 积分
- 512
- 威望
- 295
- 贡献
- 139
- 兑换币
- 0
- 注册时间
- 2012-4-23
- 在线时间
- 39 小时
|
用mc9s12xs128改了个51的12864程序 什么都不显示啊 可能是时序问题 大神们帮看看呗谢谢了
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include "init.h"
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#define LEDCPU PORTK_PK4
#define LEDCPU_dir DDRK_DDRK4
#include <MC9S12XS128.h>
/*RS=PORTA_PA0;
RW=PORTA_PA1;
EN=PORTA_PA2; */
unsigned char num;
unsigned char const table[]={0x10,0x80,0x08,0x80,0x7E,0xFC,0x24,0x80,0x18,0xFC,0xFF,0x04,0x00,0xFC,0x3E,0x80,0x22,0xF8,0x3E,0x80,0x22,0xF8,0x3E,0x80,0x22,0xFA,0x22,0x82,0x2A,0x82,0x24,0x7E};
unsigned char const zk []={0x08,0x20,0x1C,0x10,0x1C,0x1C,0xFF,0x9E,0x7F,0x1E,0x1C,0x1F,0x3E,0x1F,0x3E,0x1F,0x77,0x1F,0x41,0x3F,0x00,0x7E,0x00,0xFE,0x83,0xFC,0x7F,0xF8,0x3F,0xF0,0x0F,0xC0};
unsigned char const table2[]={0x03,0xC0,0x04,0x20,0x04,0x20,0x03,0xC0,0x0C,0x30,0x14,0x28,0x14,0x28,0x14,0x28,0x14,0x28,0x17,0xE8,0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x20,0x0E,0x70,0x0E,0x70};
unsigned char const table3[]={0x00,0x39,0x00,0x6A,0x00,0xA8,0x01,0x29,0x7E,0x2A,0xFC,0x29,0xCC,0x2A,0xCC,0x28,0xFC,0x29,0xFC,0x2A,0x7E,0x28,0x01,0x29,0x00,0xAA,0x00,0x68,0x00,0x38};
unsigned char const table4[]={"LCD12864"};
unsigned char const table5[]={"自定义显示字符"};
unsigned char const table6[]={"液晶显示"};
void delay_10us(long m)
{ // 延时m*10us
//while(m--);
unsigned long a;
for(a=15*m;a>0;a--);
}
void read_busy()
{
DDRB=0x00;
delay_10us(10);
PORTA_PA0=0;
PORTA_PA1=1;
PORTA_PA2=1;
while(PORTB&0x80);
PORTA_PA2=0;
DDRB=0Xff;
}
void write_LCD_command(unsigned char value)
{
read_busy();
PORTA_PA0=0;
PORTA_PA1=0;
PORTA_PA2=1;
PORTB=value;
delay_10us(10);
PORTA_PA2=0;
}
void write_LCD_data(unsigned char value)
{
read_busy();
PORTA_PA0=1;
PORTA_PA1=0;
PORTA_PA2=1;
PORTB=value;
delay_10us(10);
PORTA_PA2=0;
}
void CGRAM()
{
uchar i;
write_LCD_command(0x30);
write_LCD_command(0x40);
for(i=0;i<16;i++)
{
write_LCD_data(table[i*2]);
write_LCD_data(table[i*2+1]);
}
write_LCD_command(0x50);
for(i=0;i<16;i++)
{
write_LCD_data(zk[i*2]);
write_LCD_data(zk[i*2+1]);
}
write_LCD_command(0x60);
for(i=0;i<16;i++)
{
write_LCD_data(table2[i*2]);
write_LCD_data(table2[i*2+1]);
}
write_LCD_command(0x70);
for(i=0;i<16;i++)
{
write_LCD_data(table3[i*2]);
write_LCD_data(table3[i*2+1]);
}
}
//===========================================================================================
/*************************************************************/
/* 初始化12864 */
/*************************************************************/
//函数名称:LCD_Init
//函数功能:LCD初始化
//入口参数:无
//出口参数:无
void LCD_Init()
{
delay_10us(4000);
write_LCD_command(0x30);
delay_10us(10);
write_LCD_command(0x30);
delay_10us(4);
write_LCD_command(0x0C);
delay_10us(10);
write_LCD_command(0x01);
delay_10us(1000);
write_LCD_command(0x06);
}
/*************************************************************/
/* 初始化所有模块 */
/*************************************************************/
void init_all(void)
{
INIT_PLL();//时钟80M
LCD_Init(); //自己加的12864初始化
}
/*************************************************************/
/* 主函数 */
/*************************************************************/
void main()
{
LEDCPU_dir=1;
DDRE=0x00;
PUCR_PUPEE=1;
PUCR_PUPAE=1;
init_all();
LEDCPU=0;
EnableInterrupts;
DDRA=0Xff;//信号输入
DDRB=0Xff;
while(1)
{
write_LCD_command(0x80);
for(num=0;num<8;num++)
{
write_LCD_data(table6[num]);
}
write_LCD_command(0x84);
for(num=0;num<8;num++)
{
write_LCD_data(table4[num]);
}
write_LCD_command(0x90);
for(num=0;num<14;num++)
{
write_LCD_data(table5[num]);
}
CGRAM();
write_LCD_command(0x98);
write_LCD_data(0x00);
write_LCD_data(0x00);
write_LCD_command(0x99);
write_LCD_data(0x00);
write_LCD_data(0x02);
write_LCD_command(0x9A);
write_LCD_data(0x00);
write_LCD_data(0x04);
write_LCD_command(0x9B);
write_LCD_data(0x00);
write_LCD_data(0x06);
}
}
|
|