 |
:: استاذ و مشرف قسم الالكترونيات ::
تاريخ التسجيل: May 2007
المشاركات: 6,832
|
|
نشاط [ F.Abdelaziz ]
قوة السمعة:
|
|
20-06-2017, 06:08 PM
المشاركة 95
|
|
الخطوة التالية هى كتابة (طباعة) معلومات على الشاشة ، ولهذا الغرض يمكنك استخدام أربع دوال . دالتان منهم تسمحان لك بكتابة الأحرف characters ، والدالتان الأخريان تسمحان لك بكتابة السلاسل النصية strings .
يمكنك كتابة الحروف بطريقتين ، الأولى ، ببساطة كتابة الحروف بترتيب متسلسل معروف لوحدة العرض والطريقة الثانية كتابة الحروف فى السطر والعامود الذى يحدده المبرمج .
دوال كتابة (طباعة) الأحرف Functions to print characters
الدالة الأولى لكتابة الأحرف هى الدالة :
كود:
Lcd_Chr_Cp (char out_char);
هذه الدالة يتم استدعاؤها عند كتابة حرف من حروف كود أسكى ASCII code ، الموجود فى بارامتر الدخل out_char . وعند إحساس وحدة العرض بالأمر بكتابة حرف جديد فإن المؤشر ينتقل تلقائيا للموقع التالى مباشرة . لفهم أداء هذه الدالة راقب وحلل المثال التالى :
كود:
void main (void)
{
Lcd_init (); // Start the LCD.
Lcd_Chr_Cp('H'); // These functions printed letter by letter the word "Hello".
Lcd_Chr_Cp('e');
Lcd_Chr_Cp('l');
Lcd_Chr_Cp('l');
Lcd_Chr_Cp('o');
while (1) // infinite loop.
{
}
}
ويصبح البرنامج بالصيغة التالية :
كود:
// Lcd_Chr_Cp (char out_char);
// Prints character on Lcd at current cursor position.
//Both variables and literals can be passed as a character.
// Define LCD module connections.
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connection definition
void main (void)
{
Lcd_init (); // Start the LCD.
Lcd_Chr_Cp('H'); // These functions printed letter by letter the word "Hello".
Lcd_Chr_Cp('e');
Lcd_Chr_Cp('l');
Lcd_Chr_Cp('l');
Lcd_Chr_Cp('o');
while (1) // infinite loop.
{
}
}
الشكل التالى يبين المحاكاة :

لكتابة حروف من خلال إحداثيات الصفوف والأعمدة نستخدم الدالة :
كود:
Lcd_Chr (char row, char column, char out_char);
هذه الدالة تطبع الحرف out_char بالصف row والعامود column . المثال التالى يوضح لك هذا المفهوم :
كود:
void main (void)
{
Lcd_init (); // Start the LCD.
Lcd_Chr_Cp ('H'); // These functions printed letter by letter the word "Hello".
Lcd_Chr_Cp ('e');
Lcd_Chr_Cp ('l');
Lcd_Chr_Cp ('l');
Lcd_Chr_Cp ('o');
Lcd_Chr (1, 6, '1'); // prints the character 1, at row 1, column 6
Lcd_Chr (2, 7, '2'); // prints the character 2, at row 2, column 7
Lcd_Chr (3, 8, '3'); // prints the character 3, at row 3, column 8
Lcd_Chr (4, 9, '4'); // Prints the character 4, at row 4, column 9
while (1) // infinite loop.
{
}
}
كود البرنامج :
كود:
// Lcd_Chr (char row, char column, char out_char);
// Prints character on Lcd at specified position.
//Both variables and literals can be passed as a character.
// Define LCD module connections.
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connection definition
void main (void)
{
Lcd_init (); // Start the LCD.
Lcd_Chr_Cp ('H'); // These functions printed letter by letter the word "Hello".
Lcd_Chr_Cp ('e');
Lcd_Chr_Cp ('l');
Lcd_Chr_Cp ('l');
Lcd_Chr_Cp ('o');
Lcd_Chr (1, 6, '1'); // prints the character 1, at row 1, column 6
Lcd_Chr (2, 7, '2'); // prints the character 2, at row 2, column 7
Lcd_Chr (3, 8, '3'); // prints the character 3, at row 3, column 8
Lcd_Chr (4, 9, '4'); // Prints the character 4,at row 4, column 9
while (1) // infinite loop.
{
}
}
الشكل التالى يبين المحاكاة :

دوال كتابة (طباعة) سلاسل النصوص Functions to print text strings :
أيضا كتابة السلاسل النصية إما أن يتم كتابتها فى موقع المؤشر الحالى (CP) وفق سريان الكتابة أو تكتب فى موقع يحدد بإحداثيات الصف والعامود .
لكتابة سلسلة نصية عند الموقع الحالى لمؤشر الكتابة نستخدم الدالة التالية :
كود:
Lcd_Out_Cp (char * text);
هذه الدالة لها بارامتر دخل واحد وهو مؤشر للسلسلة النصية والتى تسمى هنا text . للتعرف على استخدام هذه الدالة راقب وحلل هذا المثال :
كود:
void main (void)
{
Lcd_init (); // Start the LCD.
Lcd_Out_Cp ("Hello World ...");
while (1) // infinite loop.
{
}
}
يمكن تنفيذ هذه الدالة مع سلسلة من الثوابت أو من المتغيرات ، نعرف السلاسل بالأقواس المزدوجة فى بدايتها وفى نهايتها , على سبيل المثال "Hello World ...", ، صيغة المتغير يتم إعلانها بالشكل :
كود:
char Text [20] = "Hello World ..."
البرنامج :
كود:
// Lcd_Out_Cp (char * text);
// Prints text on Lcd at current cursor position.
//Both string variables and literals can be passed as a text.
// Define LCD module connections.
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connection definition
void main (void)
{
Lcd_init (); // Start the LCD.
Lcd_Out_Cp ("Hello World ...");
while (1) // infinite loop.
{
}
}
الشكل التالى يبين المحاكاة :

لكتابة السلسلة النصية إبتداء من نقطة إحداثيات محددة نستخدم الدالة :
كود:
Lcd_Out (char row, char column, char * text);
هذه الدالة تعمل بطريقة مماثلة للدالة السابقة بإختلاف أن بيانات البارامترات تتضمن الصف والعامود . لفهم عمل هذه الدالة راقب وحلل المثال التالى :
كود:
void main (void)
{
Lcd_init (); // Start the LCD.
Lcd_Out (1, 1, "Row 1, Column 1");
Lcd_Out (2, 2, "Row 2, Column 2");
while (1) // infinite loop.
{
}
}
البرنامج :
كود:
// Lcd_Out (char row, char column, char * text);
// Prints text on Lcd starting from specified position.
//Both string variables and literals can be passed as a text.
// Define LCD module connections.
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connection definition
void main (void)
{
Lcd_init (); // Start the LCD.
Lcd_Out (1, 1, "Row 1, Column 1");
Lcd_Out (2, 2, "Row 2, Column 2");
while (1) // infinite loop.
{
}
}
الشكل التالى يبين المحاكاة :
|