| ??? 08/28/08 03:25 Modified: 08/28/08 03:26 Read: times |
#157801 - Solved first problem,now second one Responding to: ???'s previous message |
Now i am able to use printf only to this extend,for example printf("12345AB") and whatever thing you can key in,with segment displaying at differnet brigtness.Becasuse i havn't done the things that is needn't for refreshing in TImer0 ISR.
My problem now is displaying something like d in my main method.
#include <REG52.h>
#include <stdlib.h>
#include <stdio.h>
#include <absacc.h>
#define TIMER0_COUNT 0xDC11 /* 10000h - ((11,059,200 Hz / (12 * FREQ)) - 17) */
void address(unsigned char ad);
void write(unsigned char id);
char putchar(char charIN);
unsigned char a,b,c,d,e,f,g,o,i;
unsigned int seg_count=1;
void delay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
unsigned char bdata LCD_digits[8];
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;
address(1 <<seg_count);
write(LCD_digits[seg_count]); //address 1;LCD_digits 1;
seg_count = (seg_count+1) & 0x07; //limit at 8
}
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;
for(i=0;i<8;i++) //data
{
DATA =id&0x01;
CLK = 0;
CLK = 1;
id=id>>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 */
a=4;
b=7;
c=9;
d=9*7+4;
printf("%i", d);
}
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
for (iter = 0; iter <7; iter++)
{ // shift the digits left
LCD_digits[iter] = LCD_digits[iter+1];
}
LCD_digits[7] = charIN; // new digit is rightmost
}
if (charIN == 0x00)
{ // 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 |



