我现在用GN1621驱动液晶屏,不能单独操作SEG口,我想给SEG9一个0xf0,但是液晶屏全亮了。有有大佬知道问题吗?
#define unchar unsigned char #define unint unsigned int
#define unlong unsigned long
#define CS RC0 //片选端
//#define RD RC1 //读数据时钟
#define WR RC1 //写数据时钟
#define DATA RC4 //串行数据端
void DelayUs(unsigned char Time)
{
unsigned char a;
for(a=0;a<Time;a++)
{
CLRWDT();
}
}
void delay(void)
{
unchar i;
for(i=0;i<200;i++);
}
void delay_ms(unsigned char Time)
{
unsigned char a,b;
for(a=0;a<Time;a++)
{
for(b=0;b<5;b++)
{
DelayUs(197); //快1%
}
}
}
void write_byte(unchar byte,unchar length)
{
unchar i;
for(i=0;i<length;i++)
{
WR = 0;
delay();
if(byte & 0X80)
{
DATA = 1; //高位先传
}
else
{
DATA = 0;
}
byte <<= 1;
WR = 1; //WR上升沿锁存
delay();
}
}
void Write_dat(unchar dat) //写数据
{
unchar i;
CS = 1;
delay();
CS = 0; //片选低电平使能
write_byte(0XA0,3); //传3位命令码101
write_byte(0X09,6); //传6位地址码,起始地址00H
for(i=0;i<32;i++)
{
write_byte(dat,4); //传4位数据。高位先传
}
}
void Write_dat1(unchar Addr,unchar dat) //写数据
{
unchar i;
CS = 1;
delay();
CS = 0; //片选低电平使能
write_byte(0XA0,3); //传3位命令码101
write_byte(Addr,6); //传6位地址码,起始地址00H
for(i=0;i<8;i++)
{
write_byte(dat,4); //传4位数据。高位先传
}
}
void Write_cmd(unchar cmd) //写指令
{
CS = 1;
delay();
CS = 0;
write_byte(0X80,3); //传3位命令码100
write_byte(cmd,9); //传9位指令
}
void lcd_init(void)
{
delay_ms(100);
Write_cmd(0x01); //开启系统时钟
Write_cmd(0X18); //内部RC震荡
// Write_cmd(0X14); //晶体振荡
//// Write_cmd(0X07); //允许WDT暂停标志输出
//// Write_cmd(0X88); //允许IRQ输出
//// Write_cmd(0X60); //蜂鸣频率:2KHz
Write_cmd(0x29); //1/3偏置,4COM
Write_dat(0x00); //RAM清零
Write_cmd(0x03); //开显示
}
/*-------------------------------------------------
* 函数名:POWER_INITIAL
* 功能: 上电系统初始化
* 输入: 无
* 输出: 无
--------------------------------------------------*/
void POWER_INITIAL (void)
{
OSCCON = 0B01110001; //WDT 32KHZ IRCF=111=16MHZ/2=8MHZ,0.125US/T
//Bit0=1,系统时钟为内部振荡器
//Bit0=0,时钟源由FOSC<2:0>决定即编译选项时选择
INTCON = 0; //暂禁止所有中断
PORTA = 0B00000000;
TRISA = 0B00000000; //PA输入输出 0-输出 1-输入
//PA3->输出
PORTC = 0B00000000;
TRISC = 0B00000000; //PC输入输出 0-输出 1-输入
WPUA = 0B00000000; //PA端口上拉控制 1-开上拉 0-关上拉
WPUC = 0B00000000; //PC端口上拉控制 1-开上拉 0-关上拉
OPTION = 0B00001000; //Bit3=1 WDT MODE,PS=000=1:1 WDT RATE
//Bit7(PAPU)=0 ENABLED PULL UP PA
MSCKCON = 0B00000000; //Bit6->0,禁止PA4,PC5稳压输出
//Bit5->0,TIMER2时钟为Fosc
//Bit4->0,禁止LVR
CMCON0 = 0B00000111; //关闭比较器,CxIN为数字IO口
}
/*-------------------------------------------------
* 函数名: main
* 功能: 主函数
* 输入: 无
* 输出: 无
--------------------------------------------------*/
void main()
{
POWER_INITIAL(); //系统初始化
lcd_init();
while(1)
{
//Write_dat1(0x16,0x00);
//Write_dat1(0x15,0x00);
//Write_dat1(0x14,0x00);
//Write_dat1(0x13,0x00);
//Write_dat1(0x12,0x00);
//Write_dat1(0x11,0x00);
//Write_dat1(0x10,0x00);
//Write_dat1(0x0F,0x00);
//Write_dat1(0x0E,0x00);
//Write_dat1(0x0D,0x00);
//Write_dat1(0x0C,0x00);
//Write_dat1(0x0B,0x00);
//Write_dat1(0x0A,0x00);
Write_dat1(0x09,0xf0);
}
} |