头像-314605

cd422c4e1abf4d5a

个人成就

获得 0 次赞

帮助过0人

MSP430G2553使用4个IO口控制LCD的问题

之前使用P1.4到P1.7作为数据输出到LCD我已经成功但是通过改变引脚即P1.2到P1.5作为我的数据输出引脚到LCD,它就不起作用了。这是什么问题,谢谢,下面是我的代码。#define CMD 0#define DATA 1#define LCD_OUT P1OUT#define LCD_DIR P1DIR#define D4 BIT4#define D5 BIT5#define D6 BIT6#define D7 BIT7#define RS BIT2#define EN BIT3// Delay function for producing delay in 0.1 ms incrementsvoid delay(uint8_t t){uint8_t i;for(i=t; i > 0; i--)__delay_cycles(100);}// Function to pulse EN pin after data is writtenvoid pulseEN(void){LCD_OUT |= EN;delay(1);LCD_OUT &= ~EN;delay(1);}//Function to write data/command to LCDvoid lcd_write(uint8_t value uint8_t mode){if(mode == CMD)LCD_OUT &= ~RS; // Set RS -> LOW for Command modeelseLCD_OUT |= RS; // Set RS -> HIGH for Data modeLCD_OUT = ((LCD_OUT & 0x0F) | (value & 0xF0)); // Write high nibble firstpulseEN();delay(1);LCD_OUT = ((LCD_OUT & 0x0F) | ((value << 4) & 0xF0)); // Write low nibble nextpulseEN();delay(1);}// Function to print a string on LCDvoid lcd_print(char *s){while(*s){lcd_write(*s DATA);s++;}}// Function to move cursor to desired position on LCDvoid lcd_setCursor(uint8_t row uint8_t col){const uint8_t row_offsets[] = { 0x00 0x40};lcd_write(0x80 | (col + row_offsets[row]) CMD);delay(1);}// Initialize LCDvoid lcd_init(){//P2SEL &= ~(BIT6+BIT7);LCD_DIR |= (D4+D5+D6+D7+RS+EN);LCD_OUT &= ~(D4+D5+D6+D7+RS+EN);delay(150); // Wait for power up ( 15ms )lcd_write(0x33 CMD); // Initialization Sequence 1delay(50); // Wait ( 4.1 ms )lcd_write(0x32 CMD); // Initialization Sequence 2delay(1); // Wait ( 100 us )// All subsequent commands take 40 us to execute except clear & cursor return (1.64 ms)lcd_write(0x28 CMD); // 4 bit mode 2 linedelay(1);lcd_write(0x0F CMD); // Display ON Cursor ON blink ONdelay(1);lcd_write(0x01 CMD); // Clear screendelay(20);lcd_write(0x06 CMD); // Auto Increment Cursordelay(1);lcd_setCursor(00); // Goto Row 1 Column 1}void main(void){WDTCTL = WDTPW + WDTHOLD; // stop watchdoglcd_init();lcd_setCursor(05);lcd_print("hello");// lcd_setCursor(15);//lcd_print("lcd");lcd_setCursor(00);while(1);}​