chương trình trên CCS
// Program to display text on 16x2 LCD using PIC16f877a Microcontroller
#include <16F877A.h>
#use delay(clock=4000000)
//LCD Control pins
#define rs RE0
#define rw RE1
#define en RE2
//LCD Data pins
#define lcdport PORTB
void lcd_ini();
void lcdcmd(unsigned char);
void lcddata(unsigned char);
unsigned char data[20]="DPelec compa";
unsigned char data2[20]="ndphong";
unsigned int i=0;
void main(void)
{
set_tris_b(0);
set_tris_e(0);
lcd_ini(); // LCD initialization
while(data[i]!='\0')
{
lcddata(data[i]); // Call lcddata function to send characters
// one by one from "data" array
i++;
Delay_ms(300);
}
lcdcmd(0xc0);
for(i=0;i<7;i++)
{
lcddata(data2[i]);
}
}
void lcd_ini()
{
lcdcmd(0x38); // Configure the LCD in 8-bit mode, 2 line and 5x7 font
lcdcmd(0x0C); // Display On and Cursor Off
lcdcmd(0x01); // Clear display screen
lcdcmd(0x06); // Increment cursor
lcdcmd(0x80); // Set cursor position to 1st line, 1st column
}
void lcdcmd(unsigned char cmdout)
{
lcdport=cmdout; //Send command to lcdport=PORTB
rs=0;
rw=0;
en=1;
Delay_ms(10);
en=0;
}
void lcddata(unsigned char dataout)
{
lcdport=dataout; //Send data to lcdport=PORTB
rs=1;
rw=0;
en=1;
Delay_ms(10);
en=0;
}
Không có nhận xét nào:
Đăng nhận xét