问题是这样的,我在一个项目中想让LCD12864屏上的数字在我需要调节时闪烁,第3行的开头几个字符还算顺利调试好了,但最后3个字符怎么调试都没通过,要显示的字符是这样的第2行“起始 搜索 结束”,要调试的这一行也就是第三行“001 开始 247”,要求分别通过按键调节001和247的值,最后按开始键,“开始”两个字变成“xxx%”.我写的程序如下:
unsigned char DDRAM[] = {0x80,0x90,0x88,0x98};//LCD12864的四行地址码0x80,0x90,0x88,0x98
//--------------------------------------------------------------------------
// 开机画面2
//--------------------------------------------------------------------------
uchar kaijihuamian0[]= {"----搜索设备----"};
uchar kaijihuamian1[]= {"起始 搜索 结束"};
uchar kaijihuamian2[]= {"001 开始 247"};
uchar kaijihuamian3[]= { 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08};
//---------------------------------------------------------------------------------
// 函数名称: 液晶屏某一串字符闪烁按照输入的时间(单位为毫秒)频率
// 函数原型: void Flashing_LCD_N_character(r,c,w,*str,Nms)
// 参数介绍: r 是要闪烁的字符处在哪一行,值为 0 1 2 3
// c 是要闪烁的字符从第几个位置开始
// w 是要闪烁几个字符的个数
// *str 是要闪烁的字符在哪个数组
// Nms 是闪烁的频率的时间(单位ms)
//---------------------------------------------------------------------------------
void Flashing_LCD_N_character(unsigned char r,unsigned char c,unsigned char w,unsigned char *str,unsigned int Nms)
{
static unsigned int time = 0,timr = 0;
static bit kongzhi = 0;
//闪烁时的空白显示字符数组
unsigned char xdata kongshuzu[] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20};
if(time == Nms){
time = 0;
if(kongzhi == 0){
LCD_ShowString(r, c, w, str);
kongzhi = 1;
}
else{
LCD_ShowString(r, c, w, kongshuzu);
kongzhi = 0;
}
}
timr ++;
if(timr == 10){
time ++;
timr = 0;
}
}
//-----------------------------------------------------------------
// 显示字符串
// 使用此函数时应当现在ZiFuLei_YeJingPing.h中设置好#define LCD1602 1
// 否则使用的是LCD12864那么只需要把#define LCD1602后面的1改成0即可
// 另外本函数一次调用只能显示一行字符,要多行显示必须调用多次,
//-----------------------------------------------------------------
void LCD_ShowString(unsigned char r, unsigned char c,unsigned char w,unsigned char *str)
{
unsigned char i = 0;
Write_LCD_Command(DDRAM[r] + c); //写入显示的起始位置
str = str + i + c;
for(i = 0; i < w; i ++){ //循环到数组中的数据写完为止
Write_LCD_Data(*(str ++)); //写入数组中的数据
}
delay_1ms(1);
}
void main(void)
{
uchar key0_GN = 0;
uchar k = 1,k1 = 247;
recv_idx = 0;
LCD_Initialize();
LCD_ShowString(0,0,16,kaijijiemian0);
LCD_ShowString(1,0,16,kaijijiemian1);
LCD_ShowString(2,0,16,kaijijiemian2);
LCD_ShowString(3,0,16,kaijijiemian3);
delay_1ms(3000);
//Uart_ModBus_init(BNJBTL,&FRAME_SPAN,&BYTE_SPAN);
if(key1 == 1 && key2 == 1){
// Sequential_Read_24C02(0xa0, 0, Search_ADDR, 10);
if( (Search_ADDR[0] == 0xff) || (Search_ADDR[0] == 0) || (Search_ADDR[1] == 0xff) || (Search_ADDR[1] == 0) ||
(Search_ADDR[2] == 0xff) || (Search_ADDR[2] == 0) || (Search_ADDR[3] == 0xff) || (Search_ADDR[3] == 0) ||
(Search_ADDR[4] == 0xff) || (Search_ADDR[4] == 0) || (Search_ADDR[5] == 0xff) || (Search_ADDR[5] == 0) ||
(Search_ADDR[6] == 0xff) || (Search_ADDR[6] == 0) || (Search_ADDR[7] == 0xff) || (Search_ADDR[7] == 0) ||
(Search_ADDR[8] == 0xff) || (Search_ADDR[8] == 0) || (Search_ADDR[9] == 0xff) || (Search_ADDR[9] == 0)){
LCD_ShowString(0, 0, 16, kaijihuamian0);
LCD_ShowString(1, 0, 16, kaijihuamian1);
LCD_ShowString(2, 0, 16, kaijihuamian2);
LCD_ShowString(3, 0, 16, kaijihuamian3);
while(key0_GN == 0){
if(key0 == 0){
delay_1ms(20);
if(key0 == 0){
key0_GN ++;
while(key0 == 0);
while(key0_GN == 1){
Flashing_LCD_N_character(2, 0, 3, kaijihuamian2, 1000);
if(key1 == 0){
delay_1ms(20);
if(key1 == 0){
k ++;
while(key1 == 0){
kaijihuamian2[0] = k / 100 + '0';
kaijihuamian2[1] = k % 100 / 10 + '0';
kaijihuamian2[2] = k % 10 + '0';
Flashing_LCD_N_character(2, 0, 3, kaijihuamian2, 1000);
}
}
}
if(key2 == 0){
delay_1ms(20);
if(key2 == 0){
k --;
while(key2 == 0){
kaijihuamian2[0] = k / 100 + '0';
kaijihuamian2[1] = k % 100 / 10 + '0';
kaijihuamian2[2] = k % 10 + '0';
Flashing_LCD_N_character(2, 0, 3, kaijihuamian2, 1000);
}
}
}
kaijihuamian2[0] = k / 100 + '0';
kaijihuamian2[1] = k % 100 / 10 + '0';
kaijihuamian2[2] = k % 10 + '0';
if(key3 == 0){
delay_1ms(20);
if(key3 == 0){
key0_GN = 2;
while(key3 == 0);
LCD_ShowString(2, 0, 16, kaijihuamian2);
}
}
}
delay_1ms(20);
while(key0_GN == 2){
Flashing_LCD_N_character(2, 5, 3, kaijihuamian2, 1000);
if(key1 == 0){
delay_1ms(20);
if(key1 == 0){
k1 ++;
while(key1 == 0){
kaijihuamian2[13] = k1 / 100 + '0';
kaijihuamian2[14] = k1 % 100 / 10 + '0';
kaijihuamian2[15] = k1 % 10 + '0';
Flashing_LCD_N_character(2, 5, 3, kaijihuamian2, 1000);
}
}
}
if(key2 == 0){
delay_1ms(20);
if(key2 == 0){
k1 --;
while(key2 == 0){
kaijihuamian2[13] = k1 / 100 + '0';
kaijihuamian2[14] = k1 % 100 / 10 + '0';
kaijihuamian2[15] = k1 % 10 + '0';
Flashing_LCD_N_character(2, 5, 3, kaijihuamian2, 1000);
}
}
}
kaijihuamian2[13] = k1 / 100 + '0';
kaijihuamian2[14] = k1 % 100 / 10 + '0';
kaijihuamian2[15] = k1 % 10 + '0';
if(key3 == 0){
delay_1ms(20);
if(key3 == 0){
key0_GN = 3;
while(key3 == 0);
LCD_ShowString(2, 0, 16, kaijihuamian2);
delay_1ms(20);
}
}
}
}
}
}
}
}
while(1){
}
}
希望大家帮帮忙,小弟感激不尽! |