rendered paste body#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=20000000)
#define nok_sclk PIN_B0
#define nok_sda PIN_B1
#define nok_dc PIN_B2
#define nok_cs PIN_B3
#define nok_res PIN_B4
int bytefornokia;
int charsel;
/*
________________
/ 12345678 \
| |
| lcd |
| back |
| |
| |
\________________/
1: VDD - 3.3V
2: SCLK
3: SDA
4: DC
5: CS
6: GND---------
7: Vout---||--^ 4.7uF
8: RES
*/
void nokia_write_command(void) {
nok_dc=0;
nok_cs=0;
nokia_write_dorc();
nok_cs=1;
}
void nokia_write_data(void) {
nok_dc=1;
nok_cs=0;
nokia_write_dorc();
nok_cs=1;
}
void nokia_write_dorc(void) {
for (int c=8; c>0; c--) {
nok_sclk=0;
if ((bytefornokia&0x80)==0) {
nok_sda=0;
} else {
nok_sda=1;
}
nok_sclk=1;
bytefornokia=bytefornokia<<1;
}
}
void nokia_gotoxy (int xnokia, int ynokia) {
bytefornokia=(0x40|(ynokia&0x07));
nokia_write_command();
bytefornokia=(0x80|(xnokia&0x7f));
nokia_write_command();
}
void nokia_printmessage(const char* message) {
while (*message)
nokia_printchar(*message++);
}
void nokia_printchar(int c) {
charsel=c;
nokia_char();
}
void nokia_char() {
//if ((charsel < 0x20) || (charsel > 0x7b)) {
if ((charsel < 0x30) || (charsel > 0x5b)) {
//charsel = 92;
charsel = 62;
}
for (int i=0; i<5; i++) {
//bytefornokia=FontLookup[charsel - 32][i] << 1;
// bytefornokia=read_eeprom(((charsel - 32) * 5)+i) << 1;
bytefornokia=read_eeprom(((charsel - 48) * 5)+i) << 1;
nokia_write_data();
}
}
void nokia_clear() {
nok_sda=0;
nok_dc=1;
nok_cs=1;
for (int z=504; z>0; z--) {
for (int x=8; x>0; x--) {
nok_sclk=0;
nok_sclk=1;
}
}
}
void nokia_init() {
nok_sclk=0;
nok_sda=0;
nok_dc=0;
nok_cs=0;
nok_res=0;
delay_ms(10);
nok_res=0;
delay_ms(250);
nok_res=1;
nok_cs=1;
bytefornokia=0x21;
nokia_write_command();
bytefornokia=0xc5;
nokia_write_command();
bytefornokia=0x06;
nokia_write_command();
bytefornokia=0x13;
nokia_write_command();
bytefornokia=0x20;
nokia_write_command();
bytefornokia=0x0c;
nokia_write_command();
nokia_clear();
nokia_gotoxy(0,0);
}
void nokia_test_1() {
nokia_gotoxy(0,0);
for (int z=42; z>0; z--) {
for (int x=6; x>0; x--) {
bytefornokia=0b_1010_1010;
nokia_write_data();
bytefornokia=0b_0101_0101;
nokia_write_data();
}
}
}
void nokia_test_2() {
nokia_gotoxy(0,0);
bytefornokia=0b_1111_1111;
nokia_write_data();
for (int z=82; z>0; z--) {
bytefornokia=0b_0000_0001;
nokia_write_data();
}
bytefornokia=0b_1111_1111;
nokia_write_data();
for (int x=4; x>0; x--) {
bytefornokia=0b_1111_1111;
nokia_write_data();
for (int y=82; y>0; y--) {
bytefornokia=0b_0000_0000;
nokia_write_data();
}
bytefornokia=0b_1111_1111;
nokia_write_data();
}
bytefornokia=0b_1111_1111;
nokia_write_data();
for (int a=82; a>0; a--) {
bytefornokia=0b_1000_0000;
nokia_write_data();
}
bytefornokia=0b_1111_1111;
nokia_write_data();
}
void main() {
nokia_init();
delay_ms(100);
//nokia_printchar('@');
nokia_test_1();
delay_ms(10000);
nokia_test_2();
//nokia_printmessage('Seize the day');
}