/* 4bit interface Character LCD module Test Program MPU:Microchip PIC 16F84A Programer : PICkit2 +-------U-------+ R/W(LCD_PIN5)<--|RA2 RA1 |-->RS(LCD_PIN4) |RA3 RA0 |-->E(LCD_PIN6) |RA4 OSC1|<--4MHz +5V===|/MCLR OSC2|--> GND===|Vss Vdd |===+5V |RB0 RB7 |-->DB7 |RB1 RB6 |-->DB6 |RB2 RB5 |-->DB5 |RB3 RB4 |-->DB4 +---------------+ Other LCD bus line(DB0~DB3) be connected to GND. */ #include <16F84A.h> #fuses HS, NOWDT, PUT, NOPROTECT #use delay (clock=4000000) #include "C1604_4bit_interface.c" //=================================== void main() { int8 i,j; int8 b1, b2, b3, b4; // The lcd_init() function should always be called once, // near the start of your program. lcd_init(); // Clear the LCD. printf(lcd_putc, "\f"); //delay_ms(500); //Set CGRAM (8 chracters made by user) ext_char_set(); while(1) { // Test the clear screen and newline commands. // Also test that we can write to all 4 lines. printf(lcd_putc, "\fThis is 1st line"); printf(lcd_putc, "\nNext is 2nd line"); printf(lcd_putc, "\nThis is 3rd line"); printf(lcd_putc, "\nFinally 4th line"); delay_ms(3000); // Display CGRAM Chracter printf(lcd_putc, "\fCGRAM chracter\n"); lcd_send_byte(1,0x00); lcd_send_byte(1,0x01); lcd_send_byte(1,0x02); lcd_send_byte(1,0x03); lcd_send_byte(1,0x04); lcd_send_byte(1,0x05); lcd_send_byte(1,0x06); lcd_send_byte(1,0x07); delay_ms(3000); /* // Test some additional characters. printf(lcd_putc, "\fABCDEFGhijklmnop"); printf(lcd_putc, "\n1234567890123456"); printf(lcd_putc, "\n!@#$^&*(){}[]:;<"); printf(lcd_putc, "\n±²³´µ¶Þ·Þ¸ÞÊßËß­"); delay_ms(3000); */ // Clear the LCD. printf(lcd_putc, "\f"); delay_ms(500); // Test that lcd_gotoxy() works. Go to each of // the four corners and put a number in each one, // in a clockwise direction, starting with the upper // left corner. lcd_gotoxy(2, 2); printf(lcd_putc, "Show 4 corners"); lcd_gotoxy(1, 1); printf(lcd_putc, "1"); lcd_gotoxy(16, 1); printf(lcd_putc, "2"); lcd_gotoxy(16, 4); printf(lcd_putc, "3"); lcd_gotoxy(1, 4); printf(lcd_putc, "4"); delay_ms(3000); // Read the character that was written in each corner // of the LCD and display it. This tests the lcd_getc() // function. // The following test can only be done if we can read // from the LCD. If the RW pin is not used, then the // LCD is in write-only mode, and we can't do this test. // The #ifdef statement will prevent the code from // being compiled, in that case. #ifdef USE_RW_PIN // Test if lcd_getc() can read // a byte from each corner. b1 = lcd_getc(1,1); b2 = lcd_getc(16,1); b3 = lcd_getc(16,4); b4 = lcd_getc(1,4); lcd_gotoxy(1, 1); printf(lcd_putc, "\fRead these bytes\n"); printf(lcd_putc, "from 4 corners:\n\n"); printf(lcd_putc, " %c %c %c %c", b1, b2, b3, b4); delay_ms(3000); #endif //The bellow code cannot be compiled because the memory is over. // Type some characters and backspace over them. printf(lcd_putc,"\fSantechDisplay\n"); printf(lcd_putc,"CharLCM:C1604A\n"); printf(lcd_putc,"Test Program\n"); printf(lcd_putc,"controll by PIC"); delay_ms(5000); /* for (j=4;j>0;j--) { // Go to end of 2nd line. lcd_gotoxy(16, j); // Backspace over 2nd line. for(i = 0; i < 16; i++) { printf(lcd_putc," \b\b"); delay_ms(50); } } */ } }