cancel
Showing results for 
Search instead for 
Did you mean: 

how would i turn this into 4 bit mode?

j g
Associate II
Posted on December 20, 2017 at 14:06

[code]#include 'lcd.h' void lcd_delayus(unsigned int us) //blocking delay for LCD, argument is approximate number of micro-seconds to delay { unsigned char i; while(us--) { for(i=0; iBSRR=(0xff<<(LCD_D0_pin+16)); //clear data lines LCD_PORT->BSRR=(d<<lcd_d0_pin); put='' data='' on='' lines='' }='' void='' lcd_strobe(void)='' 10us='' high='' pulse='' lcd='' enable='' line='' {='' lcd_delayus(10);='' set_lcd_e();='' clr_lcd_e();='' cmdlcd(unsigned='' char='' cmd)='' sends='' a='' byte='' to='' the='' control='' register='' waitlcdbusy();='' wait='' for='' be='' not='' busy='' clr_lcd_rs();='' command='' clr_lcd_rw();='' write='' set_lcd_data(cmd);='' set='' bus='' lcd_strobe();='' apply='' putlcd(unsigned='' put)='' display='' set_lcd_rs();='' text='' set_lcd_data(put);='' initlcd(void)='' systemcoreclockupdate();='' rcc-=''>AHB1ENR|=RCC_AHB1ENR_GPIODEN; //enable LCD port clock //CONFIG LCD GPIO PINS LCD_PORT->MODER&=~( //clear pin direction settings (3u<<(2*LCD_RS_pin)) |(3u<<(2*LCD_RW_pin)) |(3u<<(2*LCD_E_pin)) |(0xffff<<(2*LCD_D0_pin)) ); LCD_PORT->MODER|=( //reset pin direction settings to digital outputs (1u<<(2*LCD_RS_pin)) |(1u<<(2*LCD_RW_pin)) |(1u<<(2*LCD_E_pin)) |(0x5555<<(2*LCD_D0_pin)) ); //LCD INIT COMMANDS clr_LCD_RS(); //all lines default low clr_LCD_RW(); clr_LCD_E(); lcd_delayus(25000); //25ms startup delay cmdLCD(0x38); //Function set: 2 Line, 8-bit, 5x7 dots cmdLCD(0x0c); //Display on, Cursor blinking command cmdLCD(0x01); //Clear LCD cmdLCD(0x06); //Entry mode, auto increment with no shift } [/code] and here is my header file. [code]#ifndef _LCD_H_ #define _LCD_H_ #define LCD_PORT GPIOD #define LCD_RS_pin 11 #define LCD_RW_pin 12 #define LCD_E_pin 13 #define LCD_D0_pin 0 #define LCD_LINE1 0x80 #define LCD_LINE2 0xc0 #define set_LCD_RS() LCD_PORT->BSRR=(1u<<lcd_rs_pin) #define='' clr_lcd_rs()='' lcd_port-=''>BSRR=(1u<<(LCD_RS_pin+16)) #define set_LCD_RW() LCD_PORT->BSRR=(1u<<lcd_rw_pin) #define='' clr_lcd_rw()='' lcd_port-=''>BSRR=(1u<<(LCD_RW_pin+16)) #define set_LCD_E() LCD_PORT->BSRR=(1u<<lcd_e_pin) #define='' clr_lcd_e()='' lcd_port-=''>BSRR=(1u<<(LCD_E_pin+16)) #define LCD_CLR() cmdLCD(0x01) #define set_LCD_bus_input() LCD_PORT->MODER&=~(0xffff<<(2*LCD_D0_pin)) #define set_LCD_bus_output() LCD_PORT->MODER|=(0x5555<<(2*LCD_D0_pin)) #include void lcd_delayus(unsigned int us); void WaitLcdBusy(void); void set_LCD_data(unsigned char d); void LCD_strobe(void); void cmdLCD(unsigned char cmd); void putLCD(unsigned char put); void initLCD(void); #endif [/code]

0 REPLIES 0