|
我給你來個試試
8255LCD1602.jpg (243.47 KB, 下載次數(shù): 67)
下載附件
2020-9-29 20:30 上傳
- #include < reg51.h >
- char xdata PORTA _at_ 0x4000; //by making PORTA with address 4000H we are selecting Port A of the 8255
- // and the CS low (select the 8255)
- char xdata PORTB _at_ 0x4001; //by making PORTB with address 4001H we are selecting Port B of the 8255
- // and the CS low (select the 8255)
- void send_command(unsigned char i);
- void send_data(unsigned char i);
- void delay();
- void main(void)
- {
- unsigned int i=0;
- unsigned char line_1[] = "51HEI Hello ";
- unsigned char line_2[] = "MICROCONTROLLER";
- send_command(0x38); // Initialize LCD in 16x2 matrix mode
- send_command(0x0E); // Display ON and cursor ON
- send_command(0x01); // Clear the LCD
- send_command(0x83); // Select first line and position of the cursor to 83H + position
- // Display the dat on LCD's first line
- for (i = 0; i < 11; i++)
- {
- send_data(line_1[i]);
- }
- send_command(0xC0); // Select the second line
- // Display the dat on LCD's second line
- for (i = 0; i < 16; i++)
- {
- send_data(line_2[i]);
- }
- while(1); //Loop forever to display the dat until the power is switched OFF
- }
- //Function to send command
- void send_command(unsigned char i)
- {
- PORTA = i; //put data into 4000H
- // Port B is connected to the command pins i.e. RS, R/W, and E
- PORTB = 0x04; //4001H = 04H (00000100B) implies E = 1, RW = 0 (Write to LCD), RS = 0 (Command to be wriiten)
- delay();
- PORTB = 0x00; //4001H = 00H (00000000B) implies E = 0 (High to low pulse), RW = 0 (Write to LCD), RS = 0 (Command to be wriiten)
- delay();
- return;
- }
- //Function to send dat
- void send_data (unsigned char i)
- {
- PORTA = i; //put data into 4000H
- // Port B is connected to the command pins i.e. RS, R/W, and E
- PORTB = 0x05; // 4001H = 05H (00000101B) implies E = 1, RW = 0 (Write to LCD), RS = 1 (Data to be wriiten to LCD)
- delay();
- PORTB = 0x01; // 4001H = 01H (0000 0001B) implies E = 0 (High to low pulse), RW = 0 (Write to LCD), RS = 1 (Data to be wriiten to LCD)
- delay();
- return;
- }
- // Function to generate delay
- void delay()
- {
- unsigned int i =0;
- for (i = 0; i < 100; i++);
- }
復(fù)制代碼
|
|