??? 08/25/08 16:08 Read: times |
#157745 - printf and putchar lcd driver |
I am programming Intel 8052 microcontroller in C.
As you can see i am programming a LCD driver out of cascaded 595 chip. For my schematic i only drew Com1, but the rest is the same and QA-QH =A-DOT. For the time being, my problem is to make my code work with printf, putchar and translation table. I believe i understand most about multiplexing so i would need more advises on programming. For later phase of my project i will need program out something similar to how lcd driver should be programmed. For example my project should be able to configure limitation of count 0000-9999 using “>” and “^” button. The digit should keep blinking whenever the digit is pointed. Save it to eeprom after setting to some value. (Blinker function) I didn’t implement the Display RAM in my code and read function as i have no idea how. I did have ideas on how to program on all the lcd functions but I need more guidance to do that. Schematic http://i67.photobucket.com/albums/h3...ng/LCD.jpg App note www.electrosnab.ru/silabs/pdf/An_Soft/an202.pdf #include <REG52.h> #include <stdlib.h> #include <stdio.h> #define TIMER0_COUNT 0xDC11 /* 10000h - ((11,059,200 Hz / (12 * FREQ)) - 17) */ void address(unsigned char ad); void write(unsigned char id); void convert(unsigned char asc); char putchar(char charIN); unsigned char a,b,c,d,e,f,g,o,i; unsigned int seg_count=0; unsigned char bdata LCD_digits[7]; sbit D0A = LCD_digits[0] ^ 0; sbit D0B = LCD_digits[0] ^ 1; // D1 is controlled by S1 and S2 sbit D0C = LCD_digits[0] ^ 2; sbit D0D = LCD_digits[0] ^ 3; sbit D0E = LCD_digits[0] ^ 4; sbit D0F = LCD_digits[0] ^ 5; sbit D0G = LCD_digits[0] ^ 6; sbit D0O = LCD_digits[0] ^ 7; sbit D1A = LCD_digits[1] ^ 0; // D2 is controlled by S3 and S4 sbit D1B = LCD_digits[1] ^ 1; sbit D1C = LCD_digits[1] ^ 2; sbit D1D = LCD_digits[1] ^ 3; sbit D1E = LCD_digits[1] ^ 4; sbit D1F = LCD_digits[1] ^ 5; sbit D1G = LCD_digits[1] ^ 6; sbit D1O = LCD_digits[1] ^ 7; sbit D2A = LCD_digits[2] ^ 0; // D3 is controlled by S5 and S6 sbit D2B = LCD_digits[2] ^ 1; sbit D2C = LCD_digits[2] ^ 2; sbit D2D = LCD_digits[2] ^ 3; sbit D2E = LCD_digits[2] ^ 4; sbit D2F = LCD_digits[2] ^ 5; sbit D2G = LCD_digits[2] ^ 6; sbit D2O = LCD_digits[2] ^ 7; sbit D3A = LCD_digits[3] ^ 0; // D4 is controlled by S7 and S8 sbit D3B = LCD_digits[3] ^ 1; sbit D3C = LCD_digits[3] ^ 2; sbit D3D = LCD_digits[3] ^ 3; sbit D3E = LCD_digits[3] ^ 4; sbit D3F = LCD_digits[3] ^ 5; sbit D3G = LCD_digits[3] ^ 6; sbit D3O = LCD_digits[3] ^ 7; sbit D4A = LCD_digits[4] ^ 0; // D5 is controlled by S9 and S10 sbit D4B = LCD_digits[4] ^ 1; sbit D4C = LCD_digits[4] ^ 2; sbit D4D = LCD_digits[4] ^ 3; sbit D4E = LCD_digits[4] ^ 4; sbit D4F = LCD_digits[4] ^ 5; sbit D4G = LCD_digits[4] ^ 6; sbit D4O = LCD_digits[4] ^ 7; sbit D5A = LCD_digits[5] ^ 0; // D6 is controlled by S11 and S12 sbit D5B = LCD_digits[5] ^ 1; sbit D5C = LCD_digits[5] ^ 2; sbit D5D = LCD_digits[5] ^ 3; sbit D5E = LCD_digits[5] ^ 4; sbit D5F = LCD_digits[5] ^ 5; sbit D5G = LCD_digits[5] ^ 6; sbit D5O = LCD_digits[5] ^ 7; sbit D6A = LCD_digits[6] ^ 0; // D6 is controlled by S11 and S12 sbit D6B = LCD_digits[6] ^ 1; sbit D6C = LCD_digits[6] ^ 2; sbit D6D = LCD_digits[6] ^ 3; sbit D6E = LCD_digits[6] ^ 4; sbit D6F = LCD_digits[6] ^ 5; sbit D6G = LCD_digits[6] ^ 6; sbit D6O = LCD_digits[6] ^ 7; sbit D7A = LCD_digits[7] ^ 0; // D6 is controlled by S11 and S12 sbit D7B = LCD_digits[7] ^ 1; sbit D7C = LCD_digits[7] ^ 2; sbit D7D = LCD_digits[7] ^ 3; sbit D7E = LCD_digits[7] ^ 4; sbit D7F = LCD_digits[7] ^ 5; sbit D7G = LCD_digits[7] ^ 6; sbit D7O = LCD_digits[7] ^ 7; const unsigned char code translation_table[128]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0 - 7;clear 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 8 - 15;clear 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 16 - 23;clear 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 24 - 31;clear 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 32 - 39;clear 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, // 40 - 47;clear 0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6, 0xBE, 0xE0, // 48 - 55;clear 0xFE, 0xF6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 56 - 63;clear 0x00, 0xee, 0x3e, 0x9C, 0x7A, 0x9e, 0x8e, 0xf6, // 64 - 71;clear 0x6E, 0x60, 0x70, 0xae, 0x1C, 0x00, 0x2A, 0x3A, // 72 - 79;clear 0xce, 0xe6, 0x0A, 0xb6, 0xe0, 0x7c, 0x00, 0x00, // 80 - 87;clear 0x00, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 88 - 95;clear 0x00, 0xee, 0x3e, 0x9C, 0x7A, 0x9e, 0x8e, 0xf6, // 96 - 103;clear 0x6E, 0x60, 0x70, 0xae, 0x1C, 0x00, 0x2A, 0x3A, // 104 - 111;clear 0xce, 0xe6, 0x0A, 0xb6, 0xe0, 0x7c, 0x00, 0x00, // 112 - 119;clear 0x00, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 120 - 127;clear }; static void timer0_isr (void) interrupt 1 using 1//highest priority { unsigned i; TR0 = 0; i = TIMER0_COUNT + TL0 + (TH0<<8); TL0 = i; TH0 = i >> 8; TR0 = 1; if(seg_count==0) { //remove switch case;to if else latency address(0x01); write(LCD_digits[0]); seg_count=1; } if(seg_count==1) { address(0x02); write(LCD_digits[1]); seg_count=2; } if(seg_count==2) { address(0x04); write(LCD_digits[2]); seg_count=3; } if(seg_count==3) { address(0x08); write(LCD_digits[3]); seg_count=4; } if(seg_count==4) { address(0x10); write(LCD_digits[4]); seg_count=5; } if(seg_count==5) { address(0x20); write(LCD_digits[5]); seg_count=6; } if(seg_count==6) { address(0x40); write(LCD_digits[6]); seg_count=7; } if(seg_count==7) { address(0x80); write(LCD_digits[7]); seg_count=0; } } void convert(unsigned char asc) { if(asc=='~'){a=0x20;return;} if(asc=='!'){a=0x10;return;} if(asc=='@'){a=0x08;return;} if(asc=='#'){a=0x04;return;} if(asc=='$'){a=0x02;return;} if(asc=='%'){a=0x01;return;} if(asc=='^'){a=0x80;return;} if(asc=='&'){a=0x40;return;} if(asc=='+'){a=0xFD;return;} if(asc==' '){a=0x00;return;} if(asc=='-'){a=0x02;return;} if(asc=='.'){a=0x01;return;} if(asc=='0'){a=0xfc;return;} if(asc=='1'){a=0x60;return;} if(asc=='2'){a=0xda;return;} if(asc=='3'){a=0xf2;return;} if(asc=='4'){a=0x66;return;} if(asc=='5'){a=0xb6;return;} if(asc=='6'){a=0xbe;return;} if(asc=='7'){a=0xe0;return;} if(asc=='8'){a=0xfe;return;} if(asc=='9'){a=0xf6;return;} if(asc=='A'||asc=='a'){a=0xee;return;} if(asc=='B'||asc=='b'){a=0x3e;return;} if(asc=='C'||asc=='c'){a=0x9C;return;} if(asc=='D'||asc=='d'){a=0x7a;return;} if(asc=='E'||asc=='e'){a=0x9e;return;} if(asc=='F'||asc=='f'){a=0x8e;return;} if(asc=='G'||asc=='g'){a=0xf6;return;} if(asc=='H'||asc=='h'){a=0x6e;return;} if(asc=='I'||asc=='i'){a=0x60;return;} if(asc=='J'||asc=='j'){a=0x70;return;} if(asc=='K'||asc=='k'){a=0xAE;return;} if(asc=='L'||asc=='l'){a=0x1c;return;} //if(asc=='M'||asc=='m'){a=0x60;return;} if(asc=='N'||asc=='n'){a=0x2a;return;} if(asc=='O'||asc=='o'){a=0x3a;return;} if(asc=='P'||asc=='p'){a=0xce;return;} if(asc=='Q'||asc=='q'){a=0xe6;return;} if(asc=='R'||asc=='r'){a=0x0a;return;} if(asc=='S'||asc=='s'){a=0xb6;return;} if(asc=='T'||asc=='t'){a=0xe0;return;} if(asc=='U'||asc=='u'){a=0x7C;return;} //if(asc=='V'||asc=='v'){a=0x60;return;} //if(asc=='W'||asc=='w'){a=0x60;return;} //if(asc=='X'||asc=='x'){a=0x60;return;} if(asc=='Y'||asc=='y'){a=0x76;return;} //if(asc=='Z'||asc=='z'){a=0x60;return;} } void address(unsigned char ad) { unsigned char i; LCS=0; for(i=0;i<8;i++) //data { DATA =ad&0x01; CLK = 0; CLK = 1; ad=ad>>1; } } void write(unsigned char id) { unsigned char i; convert(id); for(i=0;i<8;i++) //data { DATA =a&0x01; CLK = 0; CLK = 1; a=a>>1; } LCS=1; } void main() { EA = 0; /* disable interrupts */ TR0 = 0; /* stop timer 0 */ TMOD &= ~0x0F; /* clear timer 0 mode bits */ TMOD |= 0x01; /* put timer 0 into 16-bit no prescale */ TL0 = (TIMER0_COUNT & 0x00FF); TH0 = (TIMER0_COUNT >> 8); PT0 = 0; /* set low priority for timer 0 */ ET0 = 1; /* enable timer 0 interrupt */ TR0 = 1; /* start timer 0 */ EA = 1; /* enable interrupts */ while(1) { printf("12345"); } } char putchar(char charIN) { unsigned char iter = 0; if (charIN != '\n') // not a new line { if ((charIN & 0x80) == 0) { // translation necesssary charIN = translation_table [charIN]; } // quick lookup EA = 0; // prevent partial display for (iter = 0; iter < 5; iter++) { // shift the digits left LCD_digits[iter] = LCD_digits[iter+1]; } LCD_digits[5] = charIN; // new digit is rightmost EA = 1; // enable interrupts again } else // input is a newline { EA = 0; // disable interrupts for (iter = 0; iter < 8; iter++) { LCD_digits[iter] = 0x00; } // clear all digits EA = 1; // enable interrupts } if (charIN == 0xFF) { // couldn't interpret OR space charIN = ' '; } // return space return charIN; // just like putchar } |
Topic | Author | Date |
printf and putchar lcd driver | 01/01/70 00:00 | |
Why so much code expansion? | 01/01/70 00:00 | |
RE:printf and putchar lcd driver | 01/01/70 00:00 | |
Solved first problem,now second one | 01/01/70 00:00 | |
Resistors? | 01/01/70 00:00 | |
y cannot edit previous thread | 01/01/70 00:00 | |
Mistake? | 01/01/70 00:00 | |
try to contact the Webmaster | 01/01/70 00:00 | |
ANG KAH BENG![]() | 01/01/70 00:00 |