-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlcd_driver.c
72 lines (62 loc) · 1.16 KB
/
lcd_driver.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "lcd_driver.h"
void LCD_init(void)
{
SYSCTL_RCGCGPIO_R |= 0x03; // Enable clock for GPIOA GPIOB
GPIO_PORTA_DEN_R |= 0xE0;
GPIO_PORTA_DIR_R |= 0xE0; // pins 5->7 output
GPIO_PORTB_DEN_R |= 0xFF;
GPIO_PORTB_DIR_R |= 0xFF; //pins output
//initialization
delayMs(20);
LCD_command(0x30);
delayMs(5);
LCD_command(0x30);
delayUs(100);
LCD_command(0x30);
LCD_command(0x38);
LCD_command(0x06);
LCD_command(0x01); //clear
LCD_command(0x0F); //display on
}
void LCD_reset(void)
{
LCD_command(0x80);
LCD_command(0x01);
}
void LCD_data(unsigned char data)
{
GPIO_PORTA_DATA_R = 0x20; //RS = 1
GPIO_PORTB_DATA_R = data;
GPIO_PORTA_DATA_R = 0xA0;
GPIO_PORTA_DATA_R = 0;
delayUs(40);
}
void LCD_command(unsigned char command)
{
GPIO_PORTA_DATA_R = 0; // RS = 0
GPIO_PORTB_DATA_R = command;
GPIO_PORTA_DATA_R = 0x80;
GPIO_PORTA_DATA_R = 0;
if (command < 4)
delayMs(2);
else
delayUs(40);
}
void delayMs(int n) // 16 MHz CPU Clock
{
for(int i=0; i<n; i++)
{
for(int j=0; j<3180; j++)
{
}
}
}
void delayUs(int n)
{
for(int i=0; i<n; i++)
{
for(int j=0; j<3; j++)
{
}
}
}