单片机中用lcd显示电池充电
2019-04-15 18:37发布
生成海报
#include
#include "delay.h"
#define LCDPORT P0
sbit RS = P2^4;
sbit RW = P2^5;
sbit E = P2^6;
#define LCD_WRITE_DATA 1
#define LCD_WRITE_COM 0
void lcd_write(unsigned char byte, unsigned char flag)
{
if(flag)
{
RS = 1;
}
else
{
RS = 0;
}
RW = 0;
E = 1;
LCDPORT = byte;
delay_us(5);
E = 0;
}
void lcd_init()
{
delay_ms(16);
lcd_write(0x38, LCD_WRITE_COM);
delay_ms(5);
lcd_write(0x38, LCD_WRITE_COM);
delay_ms(5);
lcd_write(0x38, LCD_WRITE_COM);
delay_ms(5);
lcd_write(0x38, LCD_WRITE_COM);
delay_ms(5);
lcd_write(0x08, LCD_WRITE_COM);
delay_ms(5);
lcd_write(0x01, LCD_WRITE_COM);
delay_ms(5);
lcd_write(0x06, LCD_WRITE_COM);
delay_ms(5);
lcd_write(0x0C, LCD_WRITE_COM);
delay_ms(5);
}
void add()
{
unsigned char i = 0;
while(i < 7)
{
lcd_write(0x70, LCD_WRITE_COM);
lcd_write(0x1f, LCD_WRITE_DATA);
lcd_write(0x1f, LCD_WRITE_DATA);
lcd_write(0x1f, LCD_WRITE_DATA);
lcd_write(0x1f, LCD_WRITE_DATA);
lcd_write(0x1f, LCD_WRITE_DATA);
lcd_write(0x1f, LCD_WRITE_DATA);
lcd_write(0x1f, LCD_WRITE_DATA);
lcd_write(0x1f, LCD_WRITE_DATA);
lcd_write(4 + i + 0x80, LCD_WRITE_COM);
lcd_write(0x6, LCD_WRITE_DATA);
lcd_write(4 + i + 0x80 + 0x40, LCD_WRITE_COM);
lcd_write(0x6, LCD_WRITE_DATA);
delay_ms(255);
i++;
}
}
void lcd_elec()
{
lcd_write(0x40, LCD_WRITE_COM);
lcd_write(0x1f, LCD_WRITE_DATA);
lcd_write(0x1f, LCD_WRITE_DATA);
lcd_write(0x10, LCD_WRITE_DATA);
lcd_write(0x10, LCD_WRITE_DATA);
lcd_write(0x10, LCD_WRITE_DATA);
lcd_write(0x10, LCD_WRITE_DATA);
lcd_write(0x10, LCD_WRITE_DATA);
lcd_write(0x10, LCD_WRITE_DATA);
lcd_write(4 + 0x80, LCD_WRITE_COM);
lcd_write(0x0, LCD_WRITE_DATA);
lcd_write(0x48, LCD_WRITE_COM);
lcd_write(0x10, LCD_WRITE_DATA);
lcd_write(0x10, LCD_WRITE_DATA);
lcd_write(0x10, LCD_WRITE_DATA);
lcd_write(0x10, LCD_WRITE_DATA);
lcd_write(0x10, LCD_WRITE_DATA);
lcd_write(0x10, LCD_WRITE_DATA);
lcd_write(0x1f, LCD_WRITE_DATA);
lcd_write(0x1f, LCD_WRITE_DATA);
lcd_write(4 + 0x80 + 0x40, LCD_WRITE_COM);
lcd_write(0x1, LCD_WRITE_DATA);
lcd_write(0x50, LCD_WRITE_COM);
lcd_write(0x1f, LCD_WRITE_DATA);
lcd_write(0x1f, LCD_WRITE_DATA);
lcd_write(0x0, LCD_WRITE_DATA);
lcd_write(0x0, LCD_WRITE_DATA);
lcd_write(0x0, LCD_WRITE_DATA);
lcd_write(0x0, LCD_WRITE_DATA);
lcd_write(0x0, LCD_WRITE_DATA);
lcd_write(0x0, LCD_WRITE_DATA);
lcd_write(5 + 0x80, LCD_WRITE_COM);
lcd_write(0x2, LCD_WRITE_DATA);
lcd_write(6 + 0x80, LCD_WRITE_COM);
lcd_write(0x2, LCD_WRITE_DATA);
lcd_write(7 + 0x80, LCD_WRITE_COM);
lcd_write(0x2, LCD_WRITE_DATA);
lcd_write(8 + 0x80, LCD_WRITE_COM);
lcd_write(0x2, LCD_WRITE_DATA);
lcd_write(9 + 0x80, LCD_WRITE_COM);
lcd_write(0x2, LCD_WRITE_DATA);
lcd_write(10 + 0x80, LCD_WRITE_COM);
lcd_write(0x2, LCD_WRITE_DATA);
lcd_write(0x58, LCD_WRITE_COM);
lcd_write(0x0, LCD_WRITE_DATA);
lcd_write(0x0, LCD_WRITE_DATA);
lcd_write(0x0, LCD_WRITE_DATA);
lcd_write(0x0, LCD_WRITE_DATA);
lcd_write(0x0, LCD_WRITE_DATA);
lcd_write(0x0, LCD_WRITE_DATA);
lcd_write(0x1f, LCD_WRITE_DATA);
lcd_write(0x1f, LCD_WRITE_DATA);
lcd_write(5 + 0x80 + 0x40, LCD_WRITE_COM);
lcd_write(0x3, LCD_WRITE_DATA);
lcd_write(6 + 0x80 + 0x40, LCD_WRITE_COM);
lcd_write(0x3, LCD_WRITE_DATA);
lcd_write(7 + 0x80 + 0x40, LCD_WRITE_COM);
lcd_write(0x3, LCD_WRITE_DATA);
lcd_write(8 + 0x80 + 0x40, LCD_WRITE_COM);
lcd_write(0x3, LCD_WRITE_DATA);
lcd_write(9 + 0x80 + 0x40, LCD_WRITE_COM);
lcd_write(0x3, LCD_WRITE_DATA);
lcd_write(10 + 0x80 + 0x40, LCD_WRITE_COM);
lcd_write(0x3, LCD_WRITE_DATA);
lcd_write(0x60, LCD_WRITE_COM);
lcd_write(0x1c, LCD_WRITE_DATA);
lcd_write(0x1c, LCD_WRITE_DATA);
lcd_write(0x04, LCD_WRITE_DATA);
lcd_write(0x04, LCD_WRITE_DATA);
lcd_write(0x04, LCD_WRITE_DATA);
lcd_write(0x04, LCD_WRITE_DATA);
lcd_write(0x07, LCD_WRITE_DATA);
lcd_write(0x07, LCD_WRITE_DATA);
lcd_write(11 + 0x80, LCD_WRITE_COM);
lcd_write(0x4, LCD_WRITE_DATA);
lcd_write(0x68, LCD_WRITE_COM);
lcd_write(0x07, LCD_WRITE_DATA);
lcd_write(0x07, LCD_WRITE_DATA);
lcd_write(0x04, LCD_WRITE_DATA);
lcd_write(0x04, LCD_WRITE_DATA);
lcd_write(0x04, LCD_WRITE_DATA);
lcd_write(0x04, LCD_WRITE_DATA);
lcd_write(0x1c, LCD_WRITE_DATA);
lcd_write(0x1c, LCD_WRITE_DATA);
lcd_write(11 + 0x80 + 0x40, LCD_WRITE_COM);
lcd_write(0x5, LCD_WRITE_DATA);
delay_ms(200);
add();
}
void main()
{
lcd_init();
while(1)
{
lcd_elec();
}
}
- 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
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 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
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮