This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/MCU/Final_Design/display.c

210 lines
2.7 KiB
C
Raw Normal View History

2022-05-07 05:56:47 +00:00
#include <reg52.h>
#include "display.h"
#include "delay.h"
// DB P1
// CTL P3
sbit RS = P3 ^ 0;
sbit RW = P3 ^ 1;
sbit E = P3 ^ 2;
sbit CSA = P3 ^ 4;
sbit CSB = P3 ^ 5;
2022-05-07 06:48:25 +00:00
static unsigned char displayCache[2][8][64];
// 2 Screen 8 Page 64 Line
2022-05-07 05:56:47 +00:00
2022-05-07 06:48:25 +00:00
void addDot(unsigned char x, unsigned char y);
{
displayCache[x / 64][y / 8][x % 64] += 1 << (y % 8);
}
2022-05-07 05:56:47 +00:00
void write()
{
RW = 0;
E = 0;
E = 1;
delay(2);
E = 0;
}
void draw()
{
2022-05-07 06:48:25 +00:00
unsigned int i, j;
2022-05-07 05:56:47 +00:00
CSA = 1;
CSB = 0;
2022-05-07 06:48:25 +00:00
for(i = 0; i < 8; i++)
2022-05-07 05:56:47 +00:00
{
RS = 0;
RW = 0;
2022-05-07 06:48:25 +00:00
P1 = 0xb8 + i;
2022-05-07 05:56:47 +00:00
write();
2022-05-07 06:48:25 +00:00
P1 = 0X40;
2022-05-07 05:56:47 +00:00
write();
2022-05-07 06:48:25 +00:00
for(j = 0; j < 64; j++)
{
RS = 1;
RW = 0;
P1 = displayCache[0][i][j];
write();
}
}
2022-05-07 05:56:47 +00:00
CSA = 0;
CSB = 1;
2022-05-07 06:48:25 +00:00
for(i = 0; i < 8; i++)
2022-05-07 05:56:47 +00:00
{
RS = 0;
RW = 0;
2022-05-07 06:48:25 +00:00
P1 = 0xb8 + i;
2022-05-07 05:56:47 +00:00
write();
2022-05-07 06:48:25 +00:00
P1 = 0X40;
2022-05-07 05:56:47 +00:00
write();
2022-05-07 06:48:25 +00:00
for(j = 0; j < 64; j++)
{
RS = 1;
RW = 0;
P1 = displayCache[1][i][j];
write();
}
2022-05-07 05:56:47 +00:00
}
}
void clear()
{
unsigned int i, j;
CSA = 1;
CSB = 0;
for(i = 0; i < 8; i++)
{
RS = 0;
RW = 0;
P1 = 0xb8 + i;
write();
P1 = 0X40;
write();
for(j = 0; j < 64; j++)
{
RS = 1;
RW = 0;
P1 = 0x00;;
write();
}
}
CSA = 0;
CSB = 1;
for(i = 0; i < 8; i++)
{
RS = 0;
RW = 0;
P1 = 0xb8 + i;
write();
P1 = 0X40;
write();
for(j = 0; j < 64; j++)
{
RS = 1;
RW = 0;
P1 = 0x00;
write();
}
}
}
2022-05-07 06:48:25 +00:00
2022-05-07 05:56:47 +00:00
void init()
{
E = 0;
RS = 1;
CSA = 1;
CSB = 0;
RS = 0;
P1 = 0X3F;
write();
CSA = 0;
CSB = 1;
RS = 0;
P1 = 0X3F;
write();
}
2022-05-07 06:48:25 +00:00
2022-05-07 05:56:47 +00:00
void test()
{
unsigned int i, j;
CSA = 1;
CSB = 0;
for(i = 0; i < 8; i++)
{
RS = 0;
RW = 0;
P1 = 0xb8 + i;
write();
P1 = 0X40;
write();
for(j = 0; j < 64; j++)
{
RS = 1;
RW = 0;
P1 = 0x55;
write();
}
}
CSA = 0;
CSB = 1;
for(i = 0; i < 8; i++)
{
RS = 0;
RW = 0;
P1 = 0xb8 + i;
write();
P1 = 0X40;
write();
for(j = 0; j < 64; j++)
{
RS = 1;
RW = 0;
P1 = 0x55;;
write();
}
}
}
void writeData(unsigned char d)
{
RS = 1;
RW = 0;
P1 = d;
}
void setCommand(unsigned char d)
{
RS = 0;
RW = 0;
P1 = d;
}
void setPage(unsigned char p)
{
setCommand(0xb8 + p);
}
void setLine(unsigned char p)
{
setCommand(0xc0 + p);
}
void setY(unsigned char p)
{
setCommand(0x40 + p);
}