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
2022-05-07 13:56:47 +08:00

200 lines
No EOL
2.8 KiB
C

#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;
unsigned char sine[] = {32,33,34,36,37,39,40,42,43,44,46,47,48,49,51,52,53,54,55,56,56,57,58,59,59,60,60,61,61,61,61,61,61,61,61,61,61,61,60,60,59,59,58,57,56,56,55,54,53,52,51,49,48,47,46,44,43,42,40,39,37,36,34,33,32,30,29,27,26,24,23,21,20,19,17,16,15,14,12,11,10,9,8,7,7,6,5,4,4,3,3,2,2,2,2,2,2,2,2,2,2,2,3,3,4,4,5,6,7,7,8,9,10,11,12,14,15,16,17,19,20,21,23,24,26,27,29,30};
void write()
{
RW = 0;
E = 0;
E = 1;
delay(2);
E = 0;
}
void draw()
{
unsigned int j;
CSA = 1;
CSB = 0;
for(j = 0; j < 64; j++)
{
RS = 0;
RW = 0;
P1 = 0xb8 + (sine[j] / 8); //页
write();
P1 = 0X40 + j; //Y
write();
RS = 1;
RW = 0;
P1 = 1<<(sine[j] % 8);
write();
}
CSA = 0;
CSB = 1;
for(j = 0; j < 64; j++)
{
RS = 0;
RW = 0;
P1 = 0xb8 + (sine[63 + j] / 8); //页
write();
P1 = 0X40 + j; //Y
write();
RS = 1;
RW = 0;
P1 = 1<<(sine[j+63] % 8);
write();
}
}
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();
}
}
}
void init()
{
E = 0;
RS = 1;
CSA = 1;
CSB = 0;
RS = 0;
P1 = 0X3F;
write();
CSA = 0;
CSB = 1;
RS = 0;
P1 = 0X3F;
write();
}
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);
}