قسم الميكروكنترولر والروبوت ودوائر الاتصال بالحاسب الالي قسم المتحكمات الـ microcontroller و المعالجات microprocessor و التحكم الرقمي بالكمبيوتر CNC والانظمة الآلية والروبوت Robots

أدوات الموضوع

الصورة الرمزية 3bkarino medo
3bkarino medo
:: مهندس جيد ::
تاريخ التسجيل: Mar 2012
الدولة: دمنهور البحيرة
المشاركات: 272
نشاط [ 3bkarino medo ]
قوة السمعة:0
قديم 27-05-2012, 03:06 AM المشاركة 1   
Unhappy ما فاتده تلك الرموز في الكود #>/ Twitter FaceBook Google+



الكود ده انا لاقيته في احدي المواقع
وهو كود لتشغيل شاشة ال سي دي ملونه
السوال ما هي وظيفه الاكواد التي بعد علامه # وما هي فائده الرمز > و /



كود:
#define F_CPU 8000000UL
 
#include <avr/io.h>
#include <util/delay.h>
 
#define LCD_PORT PORTB
#define LCD_DDR  DDRB
#define LCD_CLK (1<<PB0)
#define LCD_SIO (1<<PB1)
#define LCD_CS  (1<<PB2)
#define LCD_RST (1<<PB3)
 
void LCD_Out(unsigned char Data, unsigned char isCmd) {
    if(isCmd) LCD_PORT |= LCD_CS; 
    LCD_PORT &= ~(LCD_CLK|LCD_CS);  //Clock and CS low
 
    LCD_PORT |= LCD_SIO;        //SData High
    if(isCmd) LCD_PORT &= ~LCD_SIO; //If it is a command, SData Low
 
    LCD_PORT |= LCD_CLK;        //Clock High
 
    for(char x=0; x<8; x++)    {
        LCD_PORT &= ~(LCD_SIO|LCD_CLK);        //Clock and SData low
        if(Data & 128) LCD_PORT |= LCD_SIO;      // Mask MSB - SData high if it is a 1
        LCD_PORT |= LCD_CLK;            //Clock High
        Data=Data<<1;                //Shift bits 1 left (new MSB to be read)
    }
}
 
void LCD_init(void)
{
  LCD_DDR |= (LCD_CLK | LCD_SIO | LCD_CS | LCD_RST);
 
  //Hardware Reset
  LCD_PORT &= ~LCD_RST;
  LCD_PORT |= LCD_RST;
  _delay_ms(5);
 
  LCD_PORT |= (LCD_CLK | LCD_SIO | LCD_CS);
 
  //Software Reset
  LCD_Out(0x01, 1);
  _delay_ms(10);
 
/*
  //Refresh set
  LCD_Out(0xB9, 1);
  LCD_Out(0x00, 0);
*/
 
  //Display Control
  LCD_Out(0xB6, 0);
  LCD_Out(128, 0);
  LCD_Out(128, 0);
  LCD_Out(129, 0);
  LCD_Out(84, 0);
  LCD_Out(69, 0);
  LCD_Out(82, 0);
  LCD_Out(67, 0);
 
/*
  //Temperature gradient set
  LCD_Out(0xB7, 1);
  for(char i=0; i<14; i++)  LCD_Out(0, 0);
*/
 
  //Booster Voltage On
  LCD_Out(0x03, 1);
  _delay_ms(50);  //NOTE: At least 40ms must pass between voltage on and display on.
          //Other operations may be carried out as long as the display is off
          //for this length of time.
 
/*
  //Test Mode
  LCD_Out(0x04, 1);
*/
 
/*
  // Power Control
  LCD_Out(0xBE, 1);
  LCD_Out(4, 0);
*/
 
  //Sleep Out
  LCD_Out(0x11, 1);
 
  //Display mode Normal
  LCD_Out(0x13, 1);
 
  //Display On
  LCD_Out(0x29, 1);
 
  //Set Color Lookup Table
  LCD_Out(0x2D, 1);        //Red and Green (3 bits each)
  char x, y;
  for(y = 0; y < 2; y++) {
      for(x = 0; x <= 14; x+=2) {
          LCD_Out(x, 0);
      }
  }
  //Set Color Lookup Table    //Blue (2 bits)
  LCD_Out(0, 0);
  LCD_Out(4, 0);
  LCD_Out(9, 0);
  LCD_Out(14, 0);
 
  //Set Pixel format to 8-bit color codes
  LCD_Out(0x3A, 1);
  LCD_Out(0b00000010, 0);
 
}
 
void Flash_BW(unsigned int flash_delay_ms)
{
  LCD_Out(0x13, 1);
  //All pixel ON
  LCD_Out(0x23, 1);
  _delay_ms(flash_delay_ms);
 
  LCD_Out(0x13, 1);
  //All pixel OFF
  LCD_Out(0x22, 1);
  _delay_ms(flash_delay_ms);
 
  LCD_Out(0x13, 1);
}
 
void XorScreen(void)
{
  //Screen is 96x65
 
  LCD_Out(0x2A, 1); //Set Column location
  LCD_Out(0, 0);
  LCD_Out(97, 0);
  LCD_Out(0x2B, 1); //Set Row location
  LCD_Out(0, 0);
  LCD_Out(66, 0);
  LCD_Out(0x2C, 1); //Write Data
  //Row 0-64
  for (char i=0; i<=66; i++)
  {
    //Column 0-95
    for(char j=0; j<=97; j++)
    {
      LCD_Out(j^i, 0);
    }
  }
}
 
void StripedScreen(void)
{
  unsigned char color_palate[] = {
    //BBGGGRRR
    0b00000111,    //Red
    0b00111111,    //Yellow
    0b00111100,    //Green
    0b11111000,    //Cyan
    0b11000000,    //Blue
    0b11000111,    //Magenta
    0b11111111,    //White
    0b00000111    //This should be 0x00(black) but for screen wrapping it was changed to Red
  };
 
  LCD_Out(0x13, 1);
  for (char i=0; i<8; i++)
  {
    LCD_Out(0x2A, 1);
    LCD_Out(0, 0);
    LCD_Out(97, 0);
    LCD_Out(0x2B, 1);
    LCD_Out(i*9, 0);
    LCD_Out((i*9)+8, 0);
    LCD_Out(0x2C, 1);
    for (int j=0; j<882; j++)
    {
      LCD_Out(color_palate[i], 0);
    }
  }
}
 
void Hello_World(void)
{
  //Binary representation of "Hello World"
  unsigned char Hello_World[5][5] = {
    0b10101110, 0b10001000, 0b01001010, 0b10010011, 0b00100110,
    0b10101000, 0b10001000, 0b10101010, 0b10101010, 0b10100101,
    0b11101100, 0b10001000, 0b10101010, 0b10101011, 0b00100101,
    0b10101000, 0b10001000, 0b10101010, 0b10101010, 0b10100101,
    0b10101110, 0b11101110, 0b01000101, 0b00010010, 0b10110110
  };
 
    LCD_Out(0x2A, 1);
    LCD_Out(8, 0);
    LCD_Out(87, 0);
    LCD_Out(0x2B, 1);
    LCD_Out(23, 0);
    LCD_Out(32, 0);
    LCD_Out(0x2C, 1);
    for (unsigned char i=0; i<5; i++) //Scan Rows
    {
      char h=2;
      while(h)
      {
    for (unsigned char k=0; k<5; k++) //Scan Columns
    {
      for (char j=0; j<8; j++)
      {
        if (Hello_World[i][k] & 1<<(7-j))    //Should there be a letter pixel here?
        {
          LCD_Out(0x00, 0);            //yes - draw it in black
          LCD_Out(0x00, 0);           
        }
        else
        {
          LCD_Out(0xFF, 0);            //no - draw background in white
          LCD_Out(0xFF, 0);
        }
      }
    }
    --h;
      }
    }
}
 
int main(void)
{
  LCD_init();
 
  while(1)
  {
    Flash_BW(2000);    //Flash Black and White pausing for 2 seconds on each
 
    XorScreen();    //Fill screen with an XOR pattern, pause for 2 seconds
    _delay_ms(2000);
 
    StripedScreen();    //Fill Screen with colored stripes, pause for 2 seconds
    _delay_ms(2000);
 
    Hello_World();    //Write "Hello World", pause for 10 seconds
    _delay_ms(10000);
  }
}

اعلانات

Tico
:: عضو ذهبي ::
تاريخ التسجيل: May 2012
المشاركات: 1,426
نشاط [ Tico ]
قوة السمعة:114
قديم 27-05-2012, 10:05 AM المشاركة 2   
افتراضي


الكود ده انا لاقيته في احدي المواقع
وهو كود لتشغيل شاشة ال سي دي ملونه
السوال ما هي وظيفه الاكواد التي بعد علامه # وما هي فائده الرمز > و /



كود:
#define F_CPU 8000000UL
 
#include <avr/io.h>
#include <util/delay.h>
 
#define LCD_PORT PORTB
#define LCD_DDR  DDRB
#define LCD_CLK (1<<PB0)
#define LCD_SIO (1<<PB1)
#define LCD_CS  (1<<PB2)
#define LCD_RST (1<<PB3)
 
void LCD_Out(unsigned char Data, unsigned char isCmd) {
    if(isCmd) LCD_PORT |= LCD_CS; 
    LCD_PORT &= ~(LCD_CLK|LCD_CS);  //Clock and CS low
 
    LCD_PORT |= LCD_SIO;        //SData High
    if(isCmd) LCD_PORT &= ~LCD_SIO; //If it is a command, SData Low
 
    LCD_PORT |= LCD_CLK;        //Clock High
 
    for(char x=0; x<8; x++)    {
        LCD_PORT &= ~(LCD_SIO|LCD_CLK);        //Clock and SData low
        if(Data & 128) LCD_PORT |= LCD_SIO;      // Mask MSB - SData high if it is a 1
        LCD_PORT |= LCD_CLK;            //Clock High
        Data=Data<<1;                //Shift bits 1 left (new MSB to be read)
    }
}
 
void LCD_init(void)
{
  LCD_DDR |= (LCD_CLK | LCD_SIO | LCD_CS | LCD_RST);
 
  //Hardware Reset
  LCD_PORT &= ~LCD_RST;
  LCD_PORT |= LCD_RST;
  _delay_ms(5);
 
  LCD_PORT |= (LCD_CLK | LCD_SIO | LCD_CS);
 
  //Software Reset
  LCD_Out(0x01, 1);
  _delay_ms(10);
 
/*
  //Refresh set
  LCD_Out(0xB9, 1);
  LCD_Out(0x00, 0);
*/
 
  //Display Control
  LCD_Out(0xB6, 0);
  LCD_Out(128, 0);
  LCD_Out(128, 0);
  LCD_Out(129, 0);
  LCD_Out(84, 0);
  LCD_Out(69, 0);
  LCD_Out(82, 0);
  LCD_Out(67, 0);
 
/*
  //Temperature gradient set
  LCD_Out(0xB7, 1);
  for(char i=0; i<14; i++)  LCD_Out(0, 0);
*/
 
  //Booster Voltage On
  LCD_Out(0x03, 1);
  _delay_ms(50);  //NOTE: At least 40ms must pass between voltage on and display on.
          //Other operations may be carried out as long as the display is off
          //for this length of time.
 
/*
  //Test Mode
  LCD_Out(0x04, 1);
*/
 
/*
  // Power Control
  LCD_Out(0xBE, 1);
  LCD_Out(4, 0);
*/
 
  //Sleep Out
  LCD_Out(0x11, 1);
 
  //Display mode Normal
  LCD_Out(0x13, 1);
 
  //Display On
  LCD_Out(0x29, 1);
 
  //Set Color Lookup Table
  LCD_Out(0x2D, 1);        //Red and Green (3 bits each)
  char x, y;
  for(y = 0; y < 2; y++) {
      for(x = 0; x <= 14; x+=2) {
          LCD_Out(x, 0);
      }
  }
  //Set Color Lookup Table    //Blue (2 bits)
  LCD_Out(0, 0);
  LCD_Out(4, 0);
  LCD_Out(9, 0);
  LCD_Out(14, 0);
 
  //Set Pixel format to 8-bit color codes
  LCD_Out(0x3A, 1);
  LCD_Out(0b00000010, 0);
 
}
 
void Flash_BW(unsigned int flash_delay_ms)
{
  LCD_Out(0x13, 1);
  //All pixel ON
  LCD_Out(0x23, 1);
  _delay_ms(flash_delay_ms);
 
  LCD_Out(0x13, 1);
  //All pixel OFF
  LCD_Out(0x22, 1);
  _delay_ms(flash_delay_ms);
 
  LCD_Out(0x13, 1);
}
 
void XorScreen(void)
{
  //Screen is 96x65
 
  LCD_Out(0x2A, 1); //Set Column location
  LCD_Out(0, 0);
  LCD_Out(97, 0);
  LCD_Out(0x2B, 1); //Set Row location
  LCD_Out(0, 0);
  LCD_Out(66, 0);
  LCD_Out(0x2C, 1); //Write Data
  //Row 0-64
  for (char i=0; i<=66; i++)
  {
    //Column 0-95
    for(char j=0; j<=97; j++)
    {
      LCD_Out(j^i, 0);
    }
  }
}
 
void StripedScreen(void)
{
  unsigned char color_palate[] = {
    //BBGGGRRR
    0b00000111,    //Red
    0b00111111,    //Yellow
    0b00111100,    //Green
    0b11111000,    //Cyan
    0b11000000,    //Blue
    0b11000111,    //Magenta
    0b11111111,    //White
    0b00000111    //This should be 0x00(black) but for screen wrapping it was changed to Red
  };
 
  LCD_Out(0x13, 1);
  for (char i=0; i<8; i++)
  {
    LCD_Out(0x2A, 1);
    LCD_Out(0, 0);
    LCD_Out(97, 0);
    LCD_Out(0x2B, 1);
    LCD_Out(i*9, 0);
    LCD_Out((i*9)+8, 0);
    LCD_Out(0x2C, 1);
    for (int j=0; j<882; j++)
    {
      LCD_Out(color_palate[i], 0);
    }
  }
}
 
void Hello_World(void)
{
  //Binary representation of "Hello World"
  unsigned char Hello_World[5][5] = {
    0b10101110, 0b10001000, 0b01001010, 0b10010011, 0b00100110,
    0b10101000, 0b10001000, 0b10101010, 0b10101010, 0b10100101,
    0b11101100, 0b10001000, 0b10101010, 0b10101011, 0b00100101,
    0b10101000, 0b10001000, 0b10101010, 0b10101010, 0b10100101,
    0b10101110, 0b11101110, 0b01000101, 0b00010010, 0b10110110
  };
 
    LCD_Out(0x2A, 1);
    LCD_Out(8, 0);
    LCD_Out(87, 0);
    LCD_Out(0x2B, 1);
    LCD_Out(23, 0);
    LCD_Out(32, 0);
    LCD_Out(0x2C, 1);
    for (unsigned char i=0; i<5; i++) //Scan Rows
    {
      char h=2;
      while(h)
      {
    for (unsigned char k=0; k<5; k++) //Scan Columns
    {
      for (char j=0; j<8; j++)
      {
        if (Hello_World[i][k] & 1<<(7-j))    //Should there be a letter pixel here?
        {
          LCD_Out(0x00, 0);            //yes - draw it in black
          LCD_Out(0x00, 0);           
        }
        else
        {
          LCD_Out(0xFF, 0);            //no - draw background in white
          LCD_Out(0xFF, 0);
        }
      }
    }
    --h;
      }
    }
}
 
int main(void)
{
  LCD_init();
 
  while(1)
  {
    Flash_BW(2000);    //Flash Black and White pausing for 2 seconds on each
 
    XorScreen();    //Fill screen with an XOR pattern, pause for 2 seconds
    _delay_ms(2000);
 
    StripedScreen();    //Fill Screen with colored stripes, pause for 2 seconds
    _delay_ms(2000);
 
    Hello_World();    //Write "Hello World", pause for 10 seconds
    _delay_ms(10000);
  }
}
إذا كنت تقصد هذه:
#include <avr/io.h>
#include <util/delay.h>
فهي عناوين ملفات جانبية يمكن للمبرمج ان يضيفها الى صفحة الكود الرئيسة .

اعلانات اضافية ( قم بتسجيل الدخول لاخفائها )
  

احمد مسعد محمد
:: مهندس متواجد ::
تاريخ التسجيل: May 2011
الدولة: egypt
المشاركات: 132
نشاط [ احمد مسعد محمد ]
قوة السمعة:0
قديم 28-05-2012, 12:31 PM المشاركة 3   
افتراضي


إذا كنت تقصد هذه:
#include <avr/io.h>
#include <util/delay.h>
فهي عناوين ملفات جانبية يمكن للمبرمج ان يضيفها الى صفحة الكود الرئيسة .
إذا كنت تقصد هذه:
#include <avr/io.h>
#include <util/delay.h>
فهي عناوين ملفات جانبية يمكن للمبرمج ان يضيفها الى صفحة الكود الرئيسة .
بص يا باشا العلامة دى # حاجة بيسموها preprocessor دى حجات بيتم التعامل معاها فى مرحلة preprocesing علما بئن الكود يمر بمجموعة مراحل قبل الوصول الى مرحلة file.exe اما > هذة العلامة فهى تسمى لموحدها Relational Operators
وهى تعنى اقل من واذا كانت >> فهى Bitwise Operators وتستخدم كا shift left
لاكن انت تريد تفسير هذا السطر
<include <avr/io.h#
طيب بص يا سيدى السطر دة وظيفتو على بعضو ان هوا يستدعى مكتبة اسمعا avr/io
ودى بتكون متعرف فيها اسماء register i/o بتاعت الميكرو كنترولير علشان compiler يقدر يتعامل معها و كلمة h. دى معناها header file وهوا حاطت <> علشان هوا بيستدعى header file موجود لاكن لو كان بيستدعىheader file هوا الى عملة كان هيحطة جوا " "


Tico
:: عضو ذهبي ::
تاريخ التسجيل: May 2012
المشاركات: 1,426
نشاط [ Tico ]
قوة السمعة:114
قديم 28-05-2012, 12:36 PM المشاركة 4   
Smile


بص يا باشا العلامة دى # حاجة بيسموها preprocessor دى حجات بيتم التعامل معاها فى مرحلة preprocesing علما بئن الكود يمر بمجموعة مراحل قبل الوصول الى مرحلة file.exe اما > هذة العلامة فهى تسمى لموحدها Relational Operators
وهى تعنى اقل من واذا كانت >> فهى Bitwise Operators وتستخدم كا shift left
لاكن انت تريد تفسير هذا السطر
<include <avr/io.h#
طيب بص يا سيدى السطر دة وظيفتو على بعضو ان هوا يستدعى مكتبة اسمعا avr/io
ودى بتكون متعرف فيها اسماء register i/o بتاعت الميكرو كنترولير علشان compiler يقدر يتعامل معها و كلمة h. دى معناها header file وهوا حاطت <> علشان هوا بيستدعى header file موجود لاكن لو كان بيستدعىheader file هوا الى عملة كان هيحطة جوا " "
يبدو انك أخطأت الاقتباس فلست أنا صاحب السؤال ولم اطلب اي استفسار حول الموضوع.


احمد مسعد محمد
:: مهندس متواجد ::
تاريخ التسجيل: May 2011
الدولة: egypt
المشاركات: 132
نشاط [ احمد مسعد محمد ]
قوة السمعة:0
قديم 28-05-2012, 01:10 PM المشاركة 5   
افتراضي


يبدو انك أخطأت الاقتباس فلست أنا صاحب السؤال ولم اطلب اي استفسار حول الموضوع.
اة معلش انا اسف


الصورة الرمزية 3bkarino medo
3bkarino medo
:: مهندس جيد ::
تاريخ التسجيل: Mar 2012
الدولة: دمنهور البحيرة
المشاركات: 272
نشاط [ 3bkarino medo ]
قوة السمعة:0
قديم 28-05-2012, 07:35 PM المشاركة 6   
Wink


بارك الله فيكم اخ tico و اخ احمد
وجازاكم الله كل خير
يبدو انك أخطأت الاقتباس فلست أنا صاحب السؤال ولم اطلب اي استفسار حول الموضوع.
وبعدين حصل خير هههههههه كلنا اخوه


التعديل الأخير تم بواسطة : 3bkarino medo بتاريخ 28-05-2012 الساعة 07:39 PM

Tico
:: عضو ذهبي ::
تاريخ التسجيل: May 2012
المشاركات: 1,426
نشاط [ Tico ]
قوة السمعة:114
قديم 28-05-2012, 08:50 PM المشاركة 7   
Smile ما في شي، ما في شي ..


وبعدين حصل خير هههههههه كلنا اخوه
طبعا .. طبعا .. ما في شي .. الحكاية بسيطة خالص.
المهم عندنا انك تبقى مبسوط حضرة المحقق المحترم..


الصورة الرمزية 3bkarino medo
3bkarino medo
:: مهندس جيد ::
تاريخ التسجيل: Mar 2012
الدولة: دمنهور البحيرة
المشاركات: 272
نشاط [ 3bkarino medo ]
قوة السمعة:0
قديم 28-05-2012, 11:09 PM المشاركة 8   
افتراضي


طبعا .. طبعا .. ما في شي .. الحكاية بسيطة خالص.
المهم عندنا انك تبقى مبسوط حضرة المحقق المحترم..
ههههههههه بارك الله فيك

إضافة رد

العلامات المرجعية

«     الموضوع السابق       الموضوع التالي    »
أدوات الموضوع

الانتقال السريع إلى


الساعة معتمدة بتوقيت جرينتش +3 الساعة الآن: 10:12 PM
موقع القرية الالكترونية غير مسؤول عن أي اتفاق تجاري أو تعاوني بين الأعضاء
فعلى كل شخص تحمل مسئولية نفسه إتجاه مايقوم به من بيع وشراء وإتفاق وأعطاء معلومات موقعه
التعليقات المنشورة لا تعبر عن رأي موقع القرية الالكترونية ولايتحمل الموقع أي مسؤولية قانونية حيال ذلك (ويتحمل كاتبها مسؤولية النشر)

Powered by vBulletin® Version 3.8.6, Copyright ©2000 - 2025