|
发表于 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); |
|