本帖最后由 wiisir 于 2012-4-15 09:51 编辑
PICC18编译提示出错的是:
GLCD_Wrchs(0,0,byX,0);
GLCD_Wrchs(0,0x8,byX,0);两个语句下提示:
Warning [359] E:weiMCUpicPIC18dispIV.c; 159.19 illegal conversion between pointer types
__CONFIG(1, 0x0200);所有的CONFIG都是提示
Error [194] E:weiMCUpicPIC18dispIV.c; 8.10 ")" expected
下面是程序
//****************************************************************************
#include "pic18f4620.h" //register 定义
//#include "18f4620.h" //
//#include "htc.h"
typedef unsigned char uchar;
typedef unsigned int uint;
#define GLCD_Page 0xb8
#define GLCD_Yadr 0x40
#define GLCD_Data PORTD
#define GLCD_Ctrl PORTC
#define GLCD_Cdir TRISC
#define GLCD_Ddir TRISD
#define GLCD_DI RC0 //GLCD_Ctrl.
#define GLCD_RW RC1
#define GLCD_E RC2
#define LCD_RST RE1
__CONFIG(1, 0x0200); //
__CONFIG(2, 0x000e);
__CONFIG(3, 0x8000);
__CONFIG(4, 0x00c5);
__CONFIG(5, 0x0000);
__CONFIG(6, 0x0000);
__CONFIG(7, 0x0000);
const uchar char_nubtb[10][16]=
{
/*-- 粗体; :宽度x高度=8x16 --*/
{0,0xe0,0xf0,0x18,0x08,0x18,0xf0,0xe0,0,0x0f,0x1f,0x30,0x20,0x30,0x1f,0x0f }, //0
{0,0x10,0x10,0xf8,0xf8,0,0,0,0,0x20,0x20,0x3f,0x3f,0x20,0x20,0 }, //1
{0,0x70,0x78,0x08,0x08,0x88,0xf8,0x70,0,0x30,0x38,0x2c,0x26,0x23,0x31,0x30 }, //2
{0,0x30,0x38,0x88,0x88,0xc8,0x78,0x30,0,0x18,0x38,0x20,0x20,0x31,0x1f,0x0e }, //3
{0,0,0xc0,0xe0,0x30,0xf8,0xf8,0,0,0x07,0x07,0x24,0x24,0x3f,0x3f,0x24 }, //4
{0,0xf8,0xf8,0x88,0x88,0x88,0x08,0x08,0,0x19,0x39,0x21,0x20,0x31,0x1f,0x0e }, //5
{0,0xe0,0xf0,0x98,0x88,0x98,0x18,0,0,0x0f,0x1f,0x31,0x20,0x31,0x1f,0x0e }, //6
{0,0x38,0x38,0x08,0xC8,0xF8,0x38,0x08,0,0,0,0x3F,0x3F,0,0,0 }, //7
{0,0x70,0xf8,0x88,0x08,0x88,0xf8,0x70,0,0x1c,0x3e,0x23,0x21,0x23,0x3e,0x1c }, //8
{0,0xe0,0xf0,0x18,0x08,0x18,0xf0,0xe0,0,0,0x31,0x33,0x22,0x33,0x1f,0x0f }
};
void GLCDL_WrData(uchar chdt);
void GLCDL_WrCMD(uchar chcmd);
void GLCDC_WrData(uchar chdt);
void GLCDC_WrCMD(uchar chcmd);
void GLCDR_WrData(uchar chdt);
void GLCDR_WrCMD(uchar chcmd);
void GLCD_AllClear(void);
void GLCD_Wrchs(uchar cx,uchar cy,uchar * chrt,bit beng_chn); //字符还是汉字 OK
void msDelay(unsigned int iTimes);
void LCD_CHK_BZ(void);
void main(void)
{
const uchar * cdp;
volatile uchar * byX;
volatile uchar uWord[16];
uchar ci;
cdp = &char_nubtb[0][0];
for(ci=0;ci<16;ci++)
{
uWord[ci] = *cdp++;
}
byX = &uWord[0];
GLCD_Wrchs(0,0,byX,0);
cdp = &char_nubtb[1][0];
for(ci=0;ci<16;ci++)
{
uWord[ci] = *cdp++;
}
byX = &uWord[0];
GLCD_Wrchs(0,0x8,byX,0);
do
{
asm("nop");
}while(1);
}
void GLCDL_WrData(uchar chdt) //左屏幕写数据
{
TRISE=0x7; //有时CS1/2是低电平
PORTE=0x3; //RE2:CS1, RE1:rst, RE0:CS2,
TRISE=0x0;
TRISA=0x20; //有时CS1/2是低电平
PORTA=0x3f; //RA5:CS3
TRISA=0x0;
LCD_CHK_BZ(); //if GLCD busy,waiting
GLCD_Ddir = 0xff;
GLCD_Data = chdt;
GLCD_Cdir=0x7f;
GLCD_Ctrl = 0x7d; //RC2(E):1;RC1(R/W):0;RC0(D/I):1
GLCD_Cdir=0x78;
msDelay(1);
GLCD_E=0;
}
void GLCDL_WrCMD(uchar chcmd) //左屏幕写命令
{
TRISE=0x7; //有时CS1/2是低电平
PORTE=0x3; //RE2:CS1, RE1:rst, RE0:CS2,
TRISE=0x0;
TRISA=0x20; //有时CS1/2是低电平
PORTA=0x3f; //RA5:CS3
TRISA=0x0;
LCD_CHK_BZ(); //if GLCD busy,waiting
GLCD_Ddir = 0xff;
GLCD_Data = chcmd;
GLCD_Cdir=0x7f;
GLCD_Ctrl = 0x7c; //RC2(E):1;RC1(R/W):0;RC0(D/I):0
GLCD_Cdir=0x78;
msDelay(1);
GLCD_E=0;
}
void GLCDC_WrData(uchar chdt) //中间屏幕写数据
{
TRISE=0x7; //有时CS1/2是低电平
PORTE=0x6; //RE2:CS1, RE1:rst, RE0:CS2,
TRISE=0x0;
TRISA=0x20; //有时CS1/2是低电平
PORTA=0x3f; //RA5:CS3
TRISA=0x0;
LCD_CHK_BZ(); //if GLCD busy,waiting
GLCD_Ddir = 0xff;
GLCD_Data = chdt;
GLCD_Cdir=0x7f;
GLCD_Ctrl = 0x7d; //RC2(E):1;RC1(R/W):0;RC0(D/I):1
GLCD_Cdir=0x78;
msDelay(1);
GLCD_E=0;
}
void GLCDC_WrCMD(uchar chcmd) //中间屏幕写命令
{
TRISE=0x7; //有时CS1/2是低电平
PORTE=0x6; //RE2:CS1, RE1:rst, RE0:CS2,
TRISE=0x0;
TRISA=0x20; //有时CS1/2是低电平
PORTA=0x3f; //RA5:CS3
TRISA=0x0;
LCD_CHK_BZ(); //if GLCD busy,waiting
GLCD_Ddir = 0xff;
GLCD_Data = chcmd;
GLCD_Cdir=0x7f;
GLCD_Ctrl = 0x7c; //RC2(E):1;RC1(R/W):0;RC0(D/I):0
GLCD_Cdir=0x78;
msDelay(1);
GLCD_E=0;
}
void GLCDR_WrData(uchar chdt) //右屏幕写数据
{
TRISE=0x7; //有时CS1/2是低电平
PORTE=0x7; //RE2:CS1, RE1:rst, RE0:CS2,
TRISE=0x0;
TRISA=0x20; //有时CS1/2是低电平
PORTA=0x1f; //RA5:CS3
TRISA=0x0;
LCD_CHK_BZ(); //if GLCD busy,waiting
GLCD_Ddir = 0xff;
GLCD_Data = chdt;
GLCD_Cdir=0x7f;
GLCD_Ctrl = 0x7d; //RC2(E):1;RC1(R/W):0;RC0(D/I):1
GLCD_Cdir=0x78;
msDelay(1);
GLCD_E=0;
}
void GLCDR_WrCMD(uchar chcmd) //右屏幕写命令
{
TRISE=0x7; //有时CS1/2是低电平
PORTE=0x7; //RE2:CS1, RE1:rst, RE0:CS2,
TRISE=0x0;
TRISA=0x20; //有时CS1/2是低电平
PORTA=0x1f; //RA5:CS3
TRISA=0x0;
LCD_CHK_BZ(); //if GLCD busy,waiting
GLCD_Ddir = 0xff;
GLCD_Data = chcmd;
GLCD_Cdir=0x7f;
GLCD_Ctrl = 0x7c; //RC2(E):1;RC1(R/W):0;RC0(D/I):0
GLCD_Cdir=0x78;
msDelay(1);
GLCD_E=0;
}
void GLCD_Wrchs(uchar cx,uchar cy,uchar * chrt,bit beng_chn) //字符还是汉字
{ //cx是page(0~7),cy列地址0~64,* chrt真正要写到GLCD中的data
uchar cpg,cq;
volatile uchar ci;
if(!beng_chn) cq=8;
else cq=16;
if(cy<GLCD_Yadr) //左屏
{
GLCDL_WrCMD(GLCD_Page+cx);
GLCDL_WrCMD(GLCD_Yadr+cy);
for(ci=0; ci<cq; ci++)
{
if((cy+ci)>=GLCD_Yadr)
{
cpg=ci;
GLCDC_WrCMD(GLCD_Page+cx); //写到连续的右边
GLCDC_WrCMD(cpg+cy);
for(ci=cpg; ci<cq; ci++) GLCDC_WrData(* chrt ++);
} //因为ci值到了
else GLCDL_WrData(* chrt ++);
}
GLCDL_WrCMD(GLCD_Page+cx+1); //8*16 或16*16,还有下一页写
GLCDL_WrCMD(GLCD_Yadr+cy);
for(ci=0; ci<cq; ci++)
{
if((cy+ci)>=GLCD_Yadr)
{
cpg=ci;
GLCDC_WrCMD(GLCD_Page+cx+1); //写到连续的右边,原来少掉+1一直错!!
GLCDC_WrCMD(cpg+cy);
for(ci=cpg; ci<cq; ci++) GLCDC_WrData(* chrt ++);
}
else GLCDL_WrData(* chrt ++);
}
}
else if((cy>=0x40)&&(cy<0x80)) //中屏
{
GLCDC_WrCMD(GLCD_Page+cx);
GLCDC_WrCMD(cy); //GLCD_Yadr+
for(ci=0; ci<cq; ci++)
{
if((cy+ci)>=0x80)
{
cpg=ci;
GLCDR_WrCMD(GLCD_Page+cx); //写到连续的右边
GLCDR_WrCMD(0x40); //+cy
for(ci=cpg; ci<cq; ci++) GLCDR_WrData(* chrt ++);
} //因为ci值到了
else GLCDC_WrData(* chrt ++);
}
GLCDC_WrCMD(GLCD_Page+cx+1); //8*16 或16*16,还有下一页写
GLCDC_WrCMD(cy); //GLCD_Yadr+
for(ci=0; ci<cq; ci++)
{
if((cy+ci)>=0x80)
{
cpg=ci;
GLCDR_WrCMD(GLCD_Page+cx+1); //写到连续的右边,原来少掉+1一直错!!
GLCDR_WrCMD(0x40);
for(ci=cpg; ci<cq; ci++) GLCDR_WrData(* chrt ++);
}
else GLCDC_WrData(* chrt ++);
}
}
else
{
GLCDR_WrCMD(GLCD_Page+cx);
GLCDR_WrCMD(cy-0x40);
for(ci=0; ci<cq; ci++) GLCDR_WrData(* chrt ++);
GLCDR_WrCMD(GLCD_Page+cx+1);
GLCDR_WrCMD(cy-0x40);
for(ci=0; ci<cq; ci++) GLCDR_WrData(* chrt ++);
}
}
void msDelay(unsigned int iTimes)
{
unsigned int i,j;
for(i=0;i<iTimes;i++)
for(j=0;j<135;j++) ;
}
void LCD_CHK_BZ(void)
{
GLCD_Ddir=0xff; //ready for read status
GLCD_Cdir = 0x7f;
GLCD_Ctrl = 0xfe; //Busy Check(E:1, R/W:1, D/I:0 Read Status)
GLCD_Cdir = 0x78;
do
{
GLCD_E=1;
msDelay(1);
GLCD_E=0;
}while(GLCD_Data & 0x80);
GLCD_Ddir=0x0; //data port OUT
}
only a moron will code that way.
I wonder why you would comment it out.
/quote]
__CONFIG(1, 0x0200); //
__CONFIG(2, 0x000e);
__CONFIG(3, 0x8000);
__CONFIG(4, 0x00c5);
__CONFIG(5, 0x0000);
__CONFIG(6, 0x0000);
__CONFIG(7, 0x0000);[/quote]
only a moron will code that way.
you are going out of your way to make your life more difficult than necessary.
asm(" __config" ___mkstr(w) " equ "
___mkstr(s))
/* Program a particular configuration word register with a
* literal value (e.g. __PROG_CONFIG(1, 0x0800)). Using this
* macro function with the config mask settings macros in the
* chip-specific headers may produce unexpected results.
*/
#define __PROG_CONFIG(n, x) asm(" psect config,class=CONFIG");
asm("global config_word" ___mkstr(n));
asm(" org ("___mkstr(n)"-1)*2");
asm("config_word" ___mkstr(n)":");
asm(" dw "___mkstr(x))
帮你 编译了一下,有几处地方是错的。不能用#include "pic18f4620.h" 改用#include "htc.h",我一般是#include "pic18.h"
一周热门 更多>