搜索
bottom↓
回复: 4

PIC驱动LCD,可是怎么也不出字符,高手给看看!

[复制链接]

出0入0汤圆

发表于 2010-4-24 16:52:27 | 显示全部楼层 |阅读模式
如题,使用pic16f72,lcd使用1602,使用picc(感觉picc不太好用,连定义I0脚都编不过!)
小弟新学pic,想显示一下LCD的程序,都是基础的,请帮忙看看,谢谢!

程序如下,现象是可以编过,可是烧进去后,lcd不显示,可以进入主循环)
#include<pic.h>
#define uchar unsigned char
#define uint unsinged int

__CONFIG(XT&PROTECT&PWRTEN&BOREN);
const uchar table[]="HELLO WORLD";

//#define lcdrs RC7  这里定义会编不过
//#define lcdrw RC6
//#define lcden RC5
//#define d7 RB7



void delay(uint x)
{
        uint y,z;
        for(y=x;y>0;y--)
                for(z=110;z>0;z--);
}
/*void lcdbusy()
{
        PORTB=0xff;
        lcdrw=1;
        lcdrs=0;
        lcden=1;
        asm("nop");
        asm("nop");
        while(d7);
        lcden=0;
}*/
void write_com(uchar com)
{
         //lcdbusy()
        lcdrs=0;
        PORTB=com;
        delay(5);
        lcden=1;
        delay(5);
        lcden=0;       
}

void write_data(uchar date)
{
        //lcdbusy();
        lcdrs=1;
        lcden=1;
        PORTB=date;
        delay(5);
        lcden=0;
}

void lcdinit()
{
        lcdrw=0;
        lcdrs=0;
        lcden=0;
        write_com(0x38);//设置16*2显示,8位数据接口
        write_com(0x0c);//设置开显示,不显示光标
        write_com(0x06);//设置写一个字后地址指针加1
           write_com(0x01);
        write_com(0x80+0x10);//
}
void lcdtable1()
{
    uchar i;
    for(i=0;i<11;i++)
     {
       write_data(table);
       delay(5);
     }
}

//PORTINIT:
void portinit(void)       //端口初始化
{
        PORTB=0;   //LCD数据端口
        TRISB=0;   //设为输出
        PORTC=0;    //LCD控制端口R/S,R/W,E
        TRISC=0;    //控制端口设为输出
}


//MAIN:
//****************
void main()
{
           OPTION=0X80;    //RB弱上拉使能

        portinit();   //端口初始化
        lcdinit();    //lcd初始化
        lcdtable1();        //显示HELLO WORLD
       
        while(1)
        {
             RC1=!RC1 ;
             delay(1000);
           }  //led小灯
}

结果,烧进去后,led小灯会闪动,但lcd不显示,上面的lcd显示程序有什么问题吗?好像在51里面都可以正常显示。

出0入0汤圆

发表于 2010-4-24 22:48:05 | 显示全部楼层
"感觉picc不太好用,连定义I0脚都编不过!) "

because you don't know how to use it.

"结果,烧进去后,led小灯会闪动,但lcd不显示,上面的lcd显示程序有什么问题吗?"

most likely due to wrong initiation of the lcd.

"好像在51里面都可以正常显示。"

that would have been a miracle.

here is a piece that I use that can drive a hd44780-compatible lcd, in 4 bit mode. you can compare the various functions to see why yours didn't work.

========lcd_4bit.h=================
/*
*        LCD interface header file
*        See lcd.c for more info
*/

//hardware configuration - change hardware configuration here.
//output pin definitions for 74xx164 shift register.
//do not change the definitions below for Q0..7
#define Q0        (1<<0)
#define Q1        (1<<1)
#define Q2        (1<<2)
#define Q3        (1<<3)
#define Q4        (1<<4)
#define Q5        (1<<5)
#define Q6        (1<<6)
#define Q7        (1<<7)

//#define GPIO                PORTC                //for compatability
//#define GPIO2                RC2                        //for compatability
//#define GPIO4                RC4                        //for compatability
//#define GPIO5                RC5                        //for compatability
//#define TRISIO                TRISC                //for compatability
#define LCD_DATA        PORTC                //lcd pins on portc
#define LCD_EN                RC4                //LCD_EN on gpio0
//#define LCD_CLK                RC4                //LCD_CLK on RC6
//#define LCD_SI                RC2                //spi data in on RC7
#define LCD_RS                RC5                //RS pin tied to the SO pin
#define init_ctrl        TRISC &= ~0b110000        //LCD_RS, LCD_EN, LCD_RS and LCD_CLK in output mode
//if move the pins to a different port, need to revise TRISx as well

#define LCD_Line0        0x00                //lcd line 1
#define LCD_Line1        0x40                //lcd line 2

#define LCD_8BIT        0                        //1=set the lcd in 8BIT mode, 0=in 4bit mode

//describe how LCD's data pins are connected to 164's pins
#define D0                        Q0                        //unused
#define D1                        Q1                        //unused
#define D2                        Q2                        //unused
#define D3                        Q3                        //unused
#define D4                        Q3                        //LCD's D4 connected to LCD_DATA's 7th bit
#define D5                        Q2                        //LCD's D5 connected to LCD_DATA's 0th bit
#define D6                        Q1                        //LCD's D6 connected to LCD_DATA's 5th bit
#define D7                        Q0                        //LCD's D7 connected to LCD_DATA's 2nd bit
#define init_data        TRISC &=~(D4 | D5 | D6 | D7)        //set the data lines
//#define LCD_RS                Q3                        //LCD_RS to 164's Q3/Qd
//hardware configuration

//LCD control signals
/* Display ON/OFF Control defines */
#define LCD_DISPLAY_ON                 0x0f                //0b00001111  /* Display on      */
#define LCD_DISPLAY_DOFF        0x0b                //0b00001011  /* Display off     */
#define LCD_CURSOR_ON                   0x0f                //0b00001111  /* Cursor on       */
#define LCD_CURSOR_OFF                  0x0d                //0b00001101  /* Cursor off      */
#define LCD_BLINK_ON                    0x0f                //0b00001111  /* Cursor Blink    */
#define LCD_BLINK_OFF                   0x0e                //0b00001110  /* Cursor No Blink */

/* Cursor or Display Shift defines */
//#define LCD_SHIFT_CURSOR_LEFT    0b00010011  /* Cursor shifts to the left   */
//#define LCD_SHIFT_CURSOR_RIGHT   0b00010111  /* Cursor shifts to the right  */
//#define LCD_SHIFT_DISPLAY_LEFT   0b00011011  /* Display shifts to the left  */
//#define LCD_SHIFT_DISPLAY_RIGHT  0b00011111  /* Display shifts to the right */

/* entry mode set */
#define LCD_SHIFT_CURSOR_LEFT   0x05                //0b00000101  /* Cursor shifts to the left   */
#define LCD_SHIFT_CURSOR_RIGHT  0x07                //0b00000111  /* Cursor shifts to the right  */
#define LCD_SHIFT_DISPLAY_ON           0x07                //0b00000111  /* Display shifts to the left  */
#define LCD_SHIFT_DISPLAY_OFF   0x06                //0b00000110  /* Display shifts to the right */

/* Function Set defines */
#define LCD_FOUR_BIT                           0x2f                //0b00101111  /* 4-bit Interface               */
#define LCD_EIGHT_BIT                          0x3f                //0b00111111  /* 8-bit Interface               */
#define LCD_LINE_5X7                           0x33                //0b00110011  /* 5x7 characters, single line   */
#define LCD_LINE_5X10                          0x37                //0b00110111  /* 5x10 characters               */
#define LCD_LINES_5X7                          0x3b                //0b00111011  /* 5x7 characters, multiple line */

/* write a byte to the LCD in 4 bit mode */

extern void lcd_write(unsigned char, unsigned char rs);

/* Clear and home the LCD */

extern void lcd_clear(void);

/* write a string of characters to the LCD */

extern void lcd_puts(const char * s);

/* Go to the specified position */

extern void lcd_goto(unsigned char pos);
       
/* intialize the LCD - call before anything else */

extern void lcd_init(void);

extern void lcd_putch(char);

extern void lcd_display(unsigned char LCD_Line, const char * str);

/*        Set the cursor position */

#define        lcd_cursor(x)        lcd_write(((x)&0x7F)|0x80)

extern void delay(unsigned int);
extern void delay_us(unsigned int);
extern void delay_ms(unsigned int);

出0入0汤圆

发表于 2010-4-24 22:50:30 | 显示全部楼层
here is the complete package, with a little demo program showing a 16F684-based timer.

hope it helps.

点击此处下载 ourdev_549025.rar(文件大小:19K) (原文件名:16F684 Timer - 4bit LCD.rar)

出0入0汤圆

 楼主| 发表于 2010-4-26 09:30:41 | 显示全部楼层
TKS.

昨天对程序进行仿真,发现在write_com(0x80+0x01)处错写成0x80+0x10了,改回来后,防真时能正确显示,只是不明白为何烧写进PIC后还是不显示。

感谢楼上朋友的回复。

出0入0汤圆

 楼主| 发表于 2010-4-26 13:34:35 | 显示全部楼层
问题已解决。是线路的问题,因为是自己腐蚀的一个板子,效果不是很好,有个别地方出现断线了。。。。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-9 21:12

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表