pic18驱动5110,有背光但是没有显示,请大神看看程序是否有问题

2019-07-15 15:09发布

如题,请大神们看看是不是程序的问题!#include <pic18.h>#include <stdio.h>#include <stdlib.h>
#define uint unsigned int#define uchar unsigned char #define res     PORTCbits.RC5#define sce     PORTCbits.RC4        //片选PORTAbits.RA0 #define dc      PORTCbits.RC3         //1些数据,0写指令#define sdin    PORTCbits.RC6         //数据#define sclk    PORTCbits.RC7         //时钟

void LCD_init(void);void init(void);void LCD_write_byte(unsigned char dt,unsigned char command);void delay(uint x);void LCD_set_XY(unsigned char X,unsigned char Y);void LCD_clear(void);void LCD_write_char(unsigned char x,unsigned char y,unsigned char c);void LCD_write_english_string(unsigned char X,unsigned char Y,char *s);
void main(void){    init();    LCD_init();//初始化LCD模块    LCD_clear();//清屏    while(1)    {          LCD_write_english_string(0,0," Welcome to  ");        LCD_write_english_string(0,1," Amy  studio ");        LCD_write_english_string(0,2,"amy-studio.com");        LCD_write_english_string(0,3," Nokia5110 LCD");    }//    while(1)  //  {//        asm("CLRWDT");//    }}
void init(void)  //单片机初始化{    asm("CLRWDT");    ADCON1=0x06;    TRISC=0x00;    PORTB=0x00;}
void LCD_write_byte(unsigned char dt,unsigned char command){    unsigned char i;    sce = 0;        //片选    dc = command;   //1写数据,0写指令    for(i=0;i<8;i++) //循环传送8个bit    {        if(dt&0x80)            sdin=1;        else            sdin=0;        dt=dt<<1;        sclk = 0;        asm("CLRWDT");        asm("CLRWDT");        sclk=1;     //在时钟上升沿采样    }    dc=1;    sce=1;    sdin=1;}
void LCD_init(void)     //LCD初始化{    res=0;    delay(10);    res=1;    sce=0;      //sce为高时,串行口被初始化。sce为高时忽略始时钟信号。    delay(10);    sce=1;    LCD_write_byte(0x21,0);//0b0010 0001LCD功能设置:芯片活动,水平寻址,使用扩展指令    LCD_write_byte(0xc6,0);//设置VOP值    LCD_write_byte(0x06,0);//温度校正    LCD_write_byte(0x13,0);//1:48    LCD_write_byte(0x20,0);//LCD功能设置:新品活动,水平寻址,使用基本指令    LCD_clear();    LCD_write_byte(0x0c,0);//设定显示配置:普通模式
    sce=0;}
void LCD_set_XY(unsigned char X,unsigned char Y)// 位置选择{    LCD_write_byte(0x40|Y,0);    LCD_write_byte(0x80|X,0);}
void LCD_clear(void)    //清屏{    unsigned char t;    unsigned char k;    LCD_set_XY(0,0);    for(t=0;t<6;t++)    {        for(k=0;k<84;k++)        {            LCD_write_byte(0x00,1);            asm("CLRWDT");        }    }}
void LCD_write_char(unsigned char x,unsigned char y,unsigned char c)//写数据{    unsigned char line;    c -= 32;    LCD_set_XY(x*6,y);    for(line=0;line<6;line++)        LCD_write_byte(font6x8[c][line],1);}
void delay(uint x)//延时程序{    uint a,b;    for(a=x;a>0;a--)        for(b=110;b>0;b--);}
void LCD_write_english_string(unsigned char X,unsigned char Y,char *s){    LCD_set_XY(X,Y);    while(*s)    {        LCD_write_char(X,Y,*s);        s++;    }}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
10条回答
电子微创意
2019-07-16 06:56
  1. #include <pic18.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>

  4. #define uint unsigned int
  5. #define uchar unsigned char
  6. #define res     PORTCbits.RC5
  7. #define sce     PORTCbits.RC4        //片选PORTAbits.RA0
  8. #define dc      PORTCbits.RC3         //1些数据,0写指令
  9. #define sdin    PORTCbits.RC6         //数据
  10. #define sclk    PORTCbits.RC7         //时钟


  11. void LCD_init(void);
  12. void init(void);
  13. void LCD_write_byte(unsigned char dt,unsigned char command);
  14. void delay(uint x);
  15. void LCD_set_XY(unsigned char X,unsigned char Y);
  16. void LCD_clear(void);
  17. void LCD_write_char(unsigned char x,unsigned char y,unsigned char c);
  18. void LCD_write_english_string(unsigned char X,unsigned char Y,char *s);

  19. void main(void)
  20. {
  21.     init();
  22.     LCD_init();//初始化LCD模块
  23.     LCD_clear();//清屏
  24.     while(1)
  25.     {
  26.           LCD_write_english_string(0,0," Welcome to  ");
  27.         LCD_write_english_string(0,1," Amy  studio ");
  28.         LCD_write_english_string(0,2,"amy-studio.com");
  29.         LCD_write_english_string(0,3," Nokia5110 LCD");
  30.     }
  31. //    while(1)
  32.   //  {
  33. //        asm("CLRWDT");
  34. //    }
  35. }

  36. void init(void)  //单片机初始化
  37. {
  38.     asm("CLRWDT");
  39.     ADCON1=0x06;
  40.     TRISC=0x00;
  41.     PORTB=0x00;
  42. }

  43. void LCD_write_byte(unsigned char dt,unsigned char command)
  44. {
  45.     unsigned char i;
  46.     sce = 0;        //片选
  47.     dc = command;   //1写数据,0写指令
  48.     for(i=0;i<8;i++) //循环传送8个bit
  49.     {
  50.         if(dt&0x80)
  51.             sdin=1;
  52.         else
  53.             sdin=0;
  54.         dt=dt<<1;
  55.         sclk = 0;
  56.         asm("CLRWDT");
  57.         asm("CLRWDT");
  58.         sclk=1;     //在时钟上升沿采样
  59.     }
  60.     dc=1;
  61.     sce=1;
  62.     sdin=1;
  63. }

  64. void LCD_init(void)     //LCD初始化
  65. {
  66.     res=0;
  67.     delay(10);
  68.     res=1;
  69.     sce=0;      //sce为高时,串行口被初始化。sce为高时忽略始时钟信号。
  70.     delay(10);
  71.     sce=1;
  72.     LCD_write_byte(0x21,0);//0b0010 0001LCD功能设置:芯片活动,水平寻址,使用扩展指令
  73.     LCD_write_byte(0xc6,0);//设置VOP值
  74.     LCD_write_byte(0x06,0);//温度校正
  75.     LCD_write_byte(0x13,0);//1:48
  76.     LCD_write_byte(0x20,0);//LCD功能设置:新品活动,水平寻址,使用基本指令
  77.     LCD_clear();
  78.     LCD_write_byte(0x0c,0);//设定显示配置:普通模式

  79.     sce=0;
  80. }

  81. void LCD_set_XY(unsigned char X,unsigned char Y)// 位置选择
  82. {
  83.     LCD_write_byte(0x40|Y,0);
  84.     LCD_write_byte(0x80|X,0);
  85. }

  86. void LCD_clear(void)    //清屏
  87. {
  88.     unsigned char t;
  89.     unsigned char k;
  90.     LCD_set_XY(0,0);
  91.     for(t=0;t<6;t++)
  92.     {
  93.         for(k=0;k<84;k++)
  94.         {
  95.             LCD_write_byte(0x00,1);
  96.             asm("CLRWDT");
  97.         }
  98.     }
  99. }

  100. void LCD_write_char(unsigned char x,unsigned char y,unsigned char c)//写数据
  101. {
  102.     unsigned char line;
  103.     c -= 32;
  104.     LCD_set_XY(x*6,y);
  105.     for(line=0;line<6;line++)
  106.         LCD_write_byte(font6x8[c][line],1);
  107. }

  108. void delay(uint x)//延时程序
  109. {
  110.     uint a,b;
  111.     for(a=x;a>0;a--)
  112.         for(b=110;b>0;b--);
  113. }

  114. void LCD_write_english_string(unsigned char X,unsigned char Y,char *s)
  115. {
  116.     LCD_set_XY(X,Y);
  117.     while(*s)
  118.     {
  119.         LCD_write_char(X,Y,*s);
  120.         s++;
  121.     }
  122. }
复制代码

一周热门 更多>