 |
:: استاذ و مشرف قسم الالكترونيات ::
تاريخ التسجيل: May 2007
المشاركات: 6,894
|
|
نشاط [ F.Abdelaziz ]
قوة السمعة:333
|
|
13-05-2016, 01:00 PM
المشاركة 8
|
|
البرنامج :
سوف يتم استخدام المترجم ميكروسى برو فى إنشاء روتينات (دوال) مشغل driver موديول LCD باستخدام ثلاثة خطوط . فى الوضع الافتراضى ، بداية تشغيل موديول LCD تكون فى النظام 8-bit . هذا يتطلب تسلسل من الأوامر لإعداد هذا الموديول فى النظام 4-bit . الروتينات المذكورة هنا مخصصة لموديول LCD من نوع 16X2 ، ومع ذلك ، يمكن تعديلها للعمل مع موديولات LCD من نوع آخر .
ملحوظة :
ناشر هذا البرنامج هو Jayanth Devarayanadurga ويقول أنه قام بتعديل البرنامج المكتوب بمعرفة
Rajendra Bhatt ، بغرض أن يكون لدينا دوال مثل المستخدمة ضمن المترجم ميكروسى برو نفسه ، أى :
Serial_LCD_Out
Serial_LCD_Chr
Serial_LCD_Cmd
البرنامج الكامل :
كود:
/* 3-wire Serial LCD using 74HC595
Jayanth Devarayanadurga
08/05/2013
*/
#define _LCD_FIRST_ROW 0x80 //Move cursor to the 1st row
#define _LCD_SECOND_ROW 0xC0 //Move cursor to the 2nd row
#define _LCD_THIRD_ROW 0x94 //Move cursor to the 3rd row
#define _LCD_FOURTH_ROW 0xD4 //Move cursor to the 4th row
#define _LCD_CLEAR 0x01 //Clear display
#define _LCD_RETURN_HOME 0x02 //Return cursor to home position, returns a shifted display to
//its original position. Display data RAM is unaffected.
#define _LCD_CURSOR_OFF 0x0C //Turn off cursor
#define _LCD_UNDERLINE_ON 0x0E //Underline cursor on
#define _LCD_BLINK_CURSOR_ON 0x0F //Blink cursor on
#define _LCD_MOVE_CURSOR_LEFT 0x10 //Move cursor left without changing display data RAM
#define _LCD_MOVE_CURSOR_RIGHT 0x14 //Move cursor right without changing display data RAM
#define _LCD_TURN_ON 0x0C //Turn Lcd display on
#define _LCD_TURN_OFF 0x08 //Turn Lcd display off
#define _LCD_SHIFT_LEFT 0x18 //Shift display left without changing display data RAM
#define _LCD_SHIFT_RIGHT 0x1E //Shift display right without changing display data RAM
sbit Serial_Data_Pin at GP5_bit;
sbit Serial_Clk_Pin at GP1_bit;
sbit Enable_Pin at GP2_bit;
//Function Prototypes
void Serial_LCD_Cmd(unsigned char Command);
void Serial_LCD_Chr(unsigned int row, unsigned int col, char LCDChar);
void Serial_LCD_Init();
void Serial_LCD_Out(unsigned int row, unsigned int col, unsigned char str[20]);
void Write_Nibble(unsigned short N);
// Always mention this definition statement
unsigned short Low_Nibble, High_Nibble, p, q, Mask, N, t, RS, Flag, temp;
void Delay_50ms(){
Delay_ms(50);
}
void Write_Nibble(unsigned short N){
Enable_Pin = 0;
// ****** Write RS *********
Serial_Clk_Pin = 0;
Serial_Data_Pin = RS;
Serial_Clk_Pin = 1;
Serial_Clk_Pin = 0;
// ****** End RS Write
// Shift in 4 bits
Mask = 8;
for (t=0; t<4; t++){
Flag = N & Mask;
if(Flag==0) Serial_Data_Pin = 0;
else Serial_Data_Pin = 1;
Serial_Clk_Pin = 1;
Serial_Clk_Pin = 0;
Mask = Mask >> 1;
}
// One more clock because SC and ST clks are tied
Serial_Clk_Pin = 1;
Serial_Clk_Pin = 0;
Serial_Data_Pin = 0;
Enable_Pin = 1;
Delay_us(500);
Enable_Pin = 0;
}
void Serial_LCD_Cmd(unsigned char Command)
{
RS = 0; // It is command, not data
Low_Nibble = Command & 15; // AS : Low_Nibble = Command & 0x0F;
High_Nibble = Command/16; // AS : High_Nibble = Command>>4;
Write_Nibble(High_Nibble);
Write_Nibble(Low_Nibble);
if((Command == 0x0C) || (Command == 0x01) || (Command == 0x0E) || (Command == 0x0F) || (Command == 0x10)
|| (Command == 0x1E) || (Command == 0x18) || (Command == 0x08) || (Command == 0x14)
|| (Command == 0x02))
Delay_50ms();
}
void Serial_LCD_Chr(unsigned int row, unsigned int col, char LCDChar)
{
switch(row){
case 1:
Serial_LCD_Cmd(0x80 + col-1);
break;
case 2:
Serial_LCD_Cmd(0xC0 + col-1);
break;
case 3:
Serial_LCD_Cmd(0x94 + col-1);
break;
case 4:
Serial_LCD_Cmd(0xD4 + col-1);
break;
}
RS = 1; // It is Data, not command
Low_Nibble = LCDChar & 15;//Low_Nibble = LCDChar & 0x0F; //
High_Nibble = LCDChar/16;//High_Nibble = LCDChar>>4;
Write_Nibble(High_Nibble);
Write_Nibble(Low_Nibble);
}
void Serial_LCD_Init(){
Delay_50ms();
Serial_LCD_Cmd(0x03); // Wake-Up Sequence
Delay_50ms();
Serial_LCD_Cmd(0x03);
Delay_50ms();
Serial_LCD_Cmd(0x03);
Delay_50ms();
Serial_LCD_Cmd(0x02);
Delay_50ms();
Serial_LCD_Cmd(0x28); // 4-bits, 2 lines, 5x7 font
Delay_50ms();
Serial_LCD_Cmd(0x06); // Entry mode- Auto-increment, No Display shifting
Delay_50ms();
}
void Serial_LCD_Out(unsigned int row, unsigned int col, unsigned char str[20])
{ q = strlen(str);
for (p = 0; p<q; p++){
Serial_LCD_Chr(row,col++,str[p]); // print first character on LCD
}
row = 1;
col = 1;
}
void main() {
CMCON0 = 7; // Disable Comparators
TRISIO = 0b00001000; // All Outputs except GP3
ANSEL = 0x00; // No analog i/p
Serial_LCD_Init();
Serial_LCD_Cmd(_LCD_CLEAR);
Serial_LCD_Cmd(_LCD_CURSOR_OFF);
while(1){
Serial_LCD_Out(1,1,"3-Wire");
Serial_LCD_Out(2,1,"Serial LCD");
Serial_LCD_Out(3,1,"20X4");
Serial_LCD_Out(4,1,"Using 74HC595");
Serial_LCD_Chr(1,10, '?');
}
}
النتيجة

|