屏


| 腳位 | 說明 |
|---|---|
| 1 | LED K |
| 2 | LED K |
| 3 | GND |
| 4 | GND |
| 5 | FMARK |
| 6 | SDA |
| 7 | WR |
| 8 | RS(SCL) |
| 9 | CS |
| 10 | RESET |
| 11 | IOVCC |
| 12 | IOVCC |
| 13 | VCC |
| 14 | VC |
| 15 | GND |
| 16 | GND |
| 17 | NC |
| 18 | NC |
| 19 | NC |
| 20 | NC |
| 21 | NC |
| 22 | NC |
| 23 | LED A |
| 24 | LED A |
跳線
| 腳位 | 說明 |
|---|---|
| 1 | IOVCC |
| 2 | RESET |
| 3 | CS |
| 4 | RS(SCL) |
| 5 | WR |
| 6 | SDA |
| 7 | FMARK |
| 8 | GND |
| 9 | LED K |
| 10 | VCC |
| 11 | GND |
| 12 | LED A |
main.c
#include "stc15w4k56s4.h"
#define RST P54
#define CS P43
#define SCL P42
#define WR P41
#define SDA P40
#define Command 0
#define Parameter 1
void delayms(unsigned int ms)
{
unsigned int cnt = 0;
while (ms--) {
for (cnt = 0; cnt < 1000; cnt++) {
}
}
}
void Write(unsigned char flag, unsigned char dat)
{
int i = 0;
CS = 0;
SCL = 0;
SDA = flag;
SCL = 1;
for (i = 0; i < 8; i++) {
SCL = 0;
if ((dat & 0x80) == 0x80) {
SDA = 1;
}
else {
SDA = 0;
}
dat <<= 1;
SCL = 1;
}
CS = 1;
}
void reset(void)
{
RST = 0;
delayms(100);
RST = 1;
delayms(100);
}
void init(void)
{
Write(Command, 0x11);
delayms(120);
Write(Command, 0x36);
Write(Parameter, 0x00);
Write(Command, 0x3a);
Write(Parameter, 0x05);
Write(Command, 0x2a);
Write(Parameter, 0x00);
Write(Parameter, 0x00);
Write(Parameter, 0x00);
Write(Parameter, 0xef);
Write(Command, 0x2b);
Write(Parameter, 0x00);
Write(Parameter, 0x00);
Write(Parameter, 0x00);
Write(Parameter, 0xef);
Write(Command, 0xb2);
Write(Parameter, 0x0c);
Write(Parameter, 0x0c);
Write(Parameter, 0x00);
Write(Parameter, 0x33);
Write(Parameter, 0x33);
Write(Command, 0xb7);
Write(Parameter, 0x56);
Write(Command, 0xbb);
Write(Parameter, 0x1e);
Write(Command ,0xc0);
Write(Parameter, 0x2c);
Write(Command, 0xc2);
Write(Parameter, 0x01);
Write(Command, 0xc3);
Write(Parameter, 0x13);
Write(Command, 0xc4);
Write(Parameter, 0x20);
Write(Command, 0xc6);
Write(Parameter, 0x0f);
Write(Command, 0xd0);
Write(Parameter, 0xa4);
Write(Parameter, 0xa1);
Write(Command, 0xe0);
Write(Parameter, 0xd0);
Write(Parameter, 0x03);
Write(Parameter, 0x08);
Write(Parameter, 0x0e);
Write(Parameter, 0x11);
Write(Parameter, 0x2b);
Write(Parameter, 0x3b);
Write(Parameter, 0x44);
Write(Parameter, 0x4c);
Write(Parameter, 0x2b);
Write(Parameter, 0x16);
Write(Parameter, 0x15);
Write(Parameter, 0x1e);
Write(Parameter, 0x21);
Write(Command, 0xe1);
Write(Parameter, 0xd0);
Write(Parameter, 0x03);
Write(Parameter, 0x08);
Write(Parameter, 0x0e);
Write(Parameter, 0x11);
Write(Parameter, 0x2b);
Write(Parameter, 0x3b);
Write(Parameter, 0x54);
Write(Parameter, 0x4c);
Write(Parameter, 0x2b);
Write(Parameter, 0x16);
Write(Parameter, 0x15);
Write(Parameter, 0x1e);
Write(Parameter, 0x21);
Write(Command, 0x51);
Write(Parameter, 0x20);
Write(Command, 0xe7);
Write(Parameter, 0x00);
Write(Command, 0x29);
}
void color(void)
{
unsigned int x = 0;
unsigned int y = 0;
Write(Command, 0x2c);
for (y = 0; y < 240; y++) {
for (x = 0; x < 240; x++) {
Write(Parameter, 0xf1);
Write(Parameter, 0x00);
}
}
}
void gpio_init(void)
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
}
void main(void)
{
gpio_init();
AUXR |= 0x80;
reset();
init();
color();
while (1) {
P55 = 0;
delayms(1000);
P55 = 1;
delayms(1000);
}
}
Makefile
all: sdcc main.c packihx main.ihx > main.hex flash: sudo stcgal -p /dev/ttyO2 -P stc15 -o clock_source=external main.hex clean: rm -rf main.ihx main.lst main.mem main.rst main.lk main.map main.rel main.sym main.hex
完成