I am learning 8051. I know the theory behind 7 segment display multiplexing but do not know how to code in C. Please give me code for 4 x 7 segment display multiplexing. I am using 89S51 and will use P0 and P1 for display. And my display are common cathode (CC). Please do the need full.
Please give me code
This is a forum for programmers not for copiers. If you need to cheat to pass your examp, I hope, for the sake of the industry, that you do not pass.
Erik
I am using 89S51 and will use P0 and P1 for display P0 and P1 can not source/sink enough current to give you a bright Display. So you have to use a driver IC.
Take a look to MAX7219 on http://www.maxim-ic.com
Here is my example-Programm
//********************************************************************** // C-Programm for driving a MAX7219 // a 8 digit number is printed in a string (sprintf) // and then send to the MAX7219 //********************************************************************** #include<c8051f200.h> //#include<math.h> //#include<string.h> #include<stdio.h> sbit Data7219 = P1^0; sbit Load7219 = P1^1; sbit Clk7219 = P1^2; const unsigned char Font_B[16]= { 0x7e,0x30,0x6d,0x79,0x33,0x5b,0x5f,0x70, 0x7f,0x7b,0x77,0x1f,0x4e,0x3d,0x4f,0x47 }; void Send7219 (char,char); void Send7219byte(char); void MAX7219init(); void Display(unsigned long int); //********************************************************************** void main (void) { MAX7219init(); Display(47110815);//my_weird_number while(1){} } //********************************************************************** void MAX7219init() { Data7219 =0; Load7219 =0; Clk7219 = 0; Send7219(0x09,0x00);//Decode Mode Send7219(0x0A,0x05);//Brightness Send7219(0x0B,0x07);//Scan limit Send7219(0x0C,0x01); Send7219(0x0F,0x00); } //********************************************************************** void Send7219 (char Digit,char Data) { Send7219byte(Digit); Send7219byte(Data); Data7219=0; Load7219=1; Load7219=0; } //********************************************************************** void Send7219byte (char byte) { unsigned char I; for(I=0;I<8;I++) { if (byte & 0x80) Data7219=1; else Data7219=0; Clk7219=1; byte<<=1; Clk7219=0; } } //********************************************************************** void Display (unsigned long int My_number) { unsigned char i,string[8]; sprintf(string,"%8.lx",My_number); for (i=0;i<8;i++) { if (string[i] == 0x20)//0x20 is ASCII " " Send7219(i+1,0); //send MAX7219 " " to MAX7219 else if (string[i] <= 0x39) Send7219(i+1,Font_B[string[i] - 0x30]);//0-9 else Send7219(i+1,Font_B[string[i] - 0x57]);//A-F } } //**********************************************************************
"So you have to use a driver IC."
Well, you don't have to use an IC - you could use discrete transistors...
i will use discrete transistors the day, the hell is frozen ;-)
For my display driver, I use vacuum tubes.
This has the beneficial side effect of making the 8051 seem very modern and advanced by contrast.
... and also warms the room on a chill winter's evening...
This has the beneficial side effect ...
Another benefit is that no current is required to drive the grid, just voltage.
"Another benefit is that no current is required to drive the grid..."
Just as well - cos all the current is being used up in the heater supply!
(6.3VAC, of course...)
No, I make portable equipment, so I use 6.3V DC