oiyela
Junior Member level 3
Hi,
I am currently doing my project and i need to test my microcontroller with an LCD screen, i am using HI-tech compiler on mp lab. my code builds but does not display anything or put on the LCD. Please Help
Here is what i mapped the microcontroller pins to
I am currently doing my project and i need to test my microcontroller with an LCD screen, i am using HI-tech compiler on mp lab. my code builds but does not display anything or put on the LCD. Please Help
Here is what i mapped the microcontroller pins to
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 RD4 to LCD_RS RD5 to LCD_EN RD0 to LCD_D4 RD1 to LCD_D5 RD2 to LCD_D6 RD3 to LCD_D7 Here is my software: #ifndef _XTAL_FREQ // Unless specified elsewhere, 4MHz system frequency is assumed #define _XTAL_FREQ 8000000 #endif #include <htc.h> #include "lcd.h" #define LCD_RS RD4 #define LCD_EN RD5 #define LCD_DATA PORTD #define LCD_STROBE() ((LCD_EN = 1),(LCD_EN=0)) /* write a byte to the LCD in 4 bit mode */ void lcd_write(unsigned char c) { __delay_us(40); LCD_DATA = ( ( c >> 4 ) & 0x0F ); LCD_STROBE(); LCD_DATA = ( c & 0x0F ); LCD_STROBE(); } /* * Clear and home the LCD */ void lcd_clear(void) { LCD_RS = 0; lcd_write(0x1); __delay_ms(2); } /* write a string of chars to the LCD */ void lcd_puts(const char * s) { LCD_RS = 1; // write characters while(*s) lcd_write(*s++); } /* write one character to the LCD */ void lcd_putch(char c) { LCD_RS = 1; // write characters lcd_write( c ); } /* * Go to the specified position */ void lcd_goto(unsigned char pos) { LCD_RS = 0; lcd_write(0x80+pos); } /* initialise the LCD - put into 4 bit mode */ void lcd_init() { char init_value; init_value = 0x3; TRISA=0; TRISD=0; LCD_RS = 0; LCD_EN = 0; __delay_ms(15); // wait 15mSec after power applied, LCD_DATA = init_value; LCD_STROBE(); __delay_ms(5); LCD_STROBE(); __delay_us(200); LCD_STROBE(); __delay_us(200); LCD_DATA = 2; // Four bit mode LCD_STROBE(); lcd_write(0x28); // Set interface length lcd_write(0xF); // Display On, Cursor On, Cursor Blink lcd_clear(); // Clear screen lcd_write(0x6); // Set entry Mode }
Last edited by a moderator: