-
Notifications
You must be signed in to change notification settings - Fork 0
/
chip-328.ino
91 lines (78 loc) · 3.45 KB
/
chip-328.ino
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
#include "chip328lib.h"
#include "ssd1306.h"
uint8_t keys[4][4] = {
{0x1,0x2,0x3,0xC},
{0x4,0x5,0x6,0xD},
{0x7,0x8,0x9,0xE},
{0xA,0x0,0xB,0xF}
};
uint8_t interfaceGetKey(){
int j;
for(j=0;j<4;j++){
digitalWrite(j+2, HIGH);
if(digitalRead(6) == HIGH){
digitalWrite(j+2, LOW);
return keys[0][j];
}
if(digitalRead(7) == HIGH){
digitalWrite(j+2, LOW);
return keys[1][j];
}
if(digitalRead(8) == HIGH){
digitalWrite(j+2, LOW);
return keys[2][j];
}
if(digitalRead(9) == HIGH){
digitalWrite(j+2, LOW);
return keys[3][j];
}
digitalWrite(j+2, LOW);
}
}
unsigned long current = 0, dtMillis = 0;
uint8_t chip328Display[256];
uint8_t interfacePutPixel(uint8_t x, uint8_t y, uint8_t pixel){
uint8_t collision = 0;
uint8_t pos;
if(pixel){
pos = ((x+(y/8)*64));
if(chip328Display[pos]&(0b00000001<<(y%8))) collision = 1;
chip328Display[pos] = chip328Display[pos]^(0b00000001<<(y%8));
}
return collision;
}
void interfaceDelayTimer(int value){
//if(DT!=0) DT--;
//glutTimerFunc(17, interfaceDelayTimer, 0);
}
void interfaceLoadROM(){
int i;
const PROGMEM uint8_t brix[280] = {0x6E, 0x05, 0x65, 0x00, 0x6B, 0x06, 0x6A, 0x00, 0xA3, 0x0C, 0xDA, 0xB1, 0x7A, 0x04, 0x3A, 0x40, 0x12, 0x08, 0x7B, 0x02, 0x3B, 0x12, 0x12, 0x06, 0x6C, 0x20, 0x6D, 0x1F, 0xA3, 0x10, 0xDC, 0xD1, 0x22, 0xF6, 0x60, 0x00, 0x61, 0x00, 0xA3, 0x12, 0xD0, 0x11, 0x70, 0x08, 0xA3, 0x0E, 0xD0, 0x11, 0x60, 0x40, 0xF0, 0x15, 0xF0, 0x07, 0x30, 0x00, 0x12, 0x34, 0xC6, 0x0F, 0x67, 0x1E, 0x68, 0x01, 0x69, 0xFF, 0xA3, 0x0E, 0xD6, 0x71, 0xA3, 0x10, 0xDC, 0xD1, 0x60, 0x04, 0xE0, 0xA1, 0x7C, 0xFE, 0x60, 0x06, 0xE0, 0xA1, 0x7C, 0x02, 0x60, 0x3F, 0x8C, 0x02, 0xDC, 0xD1, 0xA3, 0x0E, 0xD6, 0x71, 0x86, 0x84, 0x87, 0x94, 0x60, 0x3F, 0x86, 0x02, 0x61, 0x1F, 0x87, 0x12, 0x47, 0x1F, 0x12, 0xAC, 0x46, 0x00, 0x68, 0x01, 0x46, 0x3F, 0x68, 0xFF, 0x47, 0x00, 0x69, 0x01, 0xD6, 0x71, 0x3F, 0x01, 0x12, 0xAA, 0x47, 0x1F, 0x12, 0xAA, 0x60, 0x05, 0x80, 0x75, 0x3F, 0x00, 0x12, 0xAA, 0x60, 0x01, 0xF0, 0x18, 0x80, 0x60, 0x61, 0xFC, 0x80, 0x12, 0xA3, 0x0C, 0xD0, 0x71, 0x60, 0xFE, 0x89, 0x03, 0x22, 0xF6, 0x75, 0x01, 0x22, 0xF6, 0x45, 0x60, 0x12, 0xDE, 0x12, 0x46, 0x69, 0xFF, 0x80, 0x60, 0x80, 0xC5, 0x3F, 0x01, 0x12 , 0xCA, 0x61, 0x02, 0x80, 0x15, 0x3F, 0x01, 0x12, 0xE0, 0x80, 0x15, 0x3F, 0x01, 0x12, 0xEE, 0x80, 0x15, 0x3F, 0x01, 0x12, 0xE8, 0x60, 0x20, 0xF0, 0x18, 0xA3, 0x0E, 0x7E, 0xFF, 0x80, 0xE0, 0x80, 0x04, 0x61, 0x00, 0xD0, 0x11, 0x3E, 0x00, 0x12, 0x30, 0x12, 0xDE, 0x78, 0xFF, 0x48, 0xFE, 0x68 , 0xFF, 0x12, 0xEE, 0x78, 0x01, 0x48, 0x02, 0x68, 0x01, 0x60, 0x04, 0xF0, 0x18, 0x69, 0xFF, 0x12, 0x70, 0xA3, 0x14, 0xF5, 0x33, 0xF2, 0x65, 0xF1, 0x29, 0x63, 0x37, 0x64, 0x00, 0xD3, 0x45, 0x73, 0x05, 0xF2, 0x29, 0xD3, 0x45, 0x00, 0xEE, 0xE0, 0x00, 0x80, 0x00, 0xFC, 0x00, 0xAA, 0x00, 0x00, 0x00, 0x00, 0x00};
for(i=0;i<280;i++){
chip328MemoryWrite(i+512, brix[i]);
}
}
void setup() {
//Linhas do teclado
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
//Colunas do teclado
pinMode(6, INPUT);
pinMode(7, INPUT);
pinMode(8, INPUT);
pinMode(9, INPUT);
interfaceLoadROM();
chip328Begin();
ssd1306_128x64_i2c_init();
ssd1306_fillScreen( 0x00 );
}
void loop() {
chip328Emulate();
DT = 0; //Implementar o DT--;
}