الكود ده انا لاقيته في احدي المواقع
وهو كود لتشغيل شاشة ال سي دي ملونه
السوال ما هي وظيفه الاكواد التي بعد علامه # وما هي فائده الرمز > و /
كود:
#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);
}
}