打印

真诚求教PIC18单片机C(PICC18)编译的问题

[复制链接]
4065|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
Wayner|  楼主 | 2012-4-15 09:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 Wayner 于 2012-4-15 10:51 编辑

程序结构在Keil C51下编译很正常,其实也是用过的一些函数定义。现在移植到PICC18下使用就不正常了。可能也是我的C语言功底薄了,不知怎么办了。
#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
}

//*************************************
GLCD_Wrchs(0,0,byX,0);
GLCD_Wrchs(0,0x8,byX,0);两个语句下提示:
Warning [359] E:\wei\MCU\pic\PIC18\dispIV.c; 159.19 illegal conversion between pointer types

__CONFIG(1, 0x0200);所有的CONFIG都是提示
Error   [194] E:\wei\MCU\pic\PIC18\dispIV.c; 8.10 ")" expected
沙发
Wayner|  楼主 | 2012-4-15 09:56 | 只看该作者
PICC18下指针(常数)的问题

使用特权

评论回复
板凳
Wayner|  楼主 | 2012-4-15 10:51 | 只看该作者
找到一个BUG了,函数void GLCD_Wrchs(uchar cx,uchar cy,uchar * chrt,bit beng_chn); 多加一个 const,即在uchar * chrt前加,就行了.现在还是配置CONFIG出错

使用特权

评论回复
地板
Wayner|  楼主 | 2012-4-15 11:48 | 只看该作者
#include "pic18f4620.h" 改成#include "htc.h",CONFIG配置位的问题不再提示了,但出现如下错误

Advisory[1233] Employing 18F4620 errata work-arounds:
Advisory[1234]  * Corrupted fast interrupt shadow registers
Advisory[1234]  * Data in RAM location can be corrupted if async. reset occurs during write

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

53

主题

848

帖子

1

粉丝