jayanth.devarayanadurga
Banned
- Joined
- Dec 4, 2012
- Messages
- 4,280
- Helped
- 822
- Reputation
- 1,654
- Reaction score
- 791
- Trophy points
- 1,393
- Location
- Bangalore, India
- Activity points
- 0
I have written a 7 Segment display Code but it is not working. Can somebody find what is the error?
I am using PIC16F887 at 4 MHz and MAX7219 7 Segment Driver. I am driving 8 X 7-Segments. My code displays any integer value. If integer value is passed it is converted to String and displayed on 7-Segment(s).
mikroC PRO PIC 6.0.1 Code v1.0.0
Here is new code. It is now displaying the digits but only one or two digits gets displayed and diplay flickers.
mikroC PRO PIC 6.0.1 Code v1.0.1
I am using PIC16F887 at 4 MHz and MAX7219 7 Segment Driver. I am driving 8 X 7-Segments. My code displays any integer value. If integer value is passed it is converted to String and displayed on 7-Segment(s).
mikroC PRO PIC 6.0.1 Code v1.0.0
Code C - [expand] 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 //********************************************************************** // C-Programm for driving a MAX7219 // a 8 digit number is printed in a string (sprintf) // and then send to the MAX7219 //********************************************************************** #define Data7219 RB0_bit #define Load7219 RB1_bit #define Clk7219 RB2_bit 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) { TRISB = 0x00; PORTB = 0x00; MAX7219init(); Display(47110815);//my_weird_number while(1){Display(47110815);} //my_weird_number} } //********************************************************************** 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]; LongToStr(My_number, string); 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 } }
Here is new code. It is now displaying the digits but only one or two digits gets displayed and diplay flickers.
mikroC PRO PIC 6.0.1 Code v1.0.1
Code C - [expand] 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 92 93 94 //********************************************************************** // C-Programm for driving a MAX7219 // a 8 digit number is printed in a string (sprintf) // and then send to the MAX7219 //********************************************************************** #define Data7219 RB0_bit #define Load7219 RB1_bit #define Clk7219 RB2_bit 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) { TRISB = 0x00; PORTB = 0x00; ANSEL = 0x00; ANSELH = 0x00; ADCON1 = 0x00; CM1CON0 = 0x00; CM2CON0 = 0x00; MAX7219init(); Display(47110815);//my_weird_number while(1){;}//Display(47110815);} //my_weird_number} } //********************************************************************** 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]; LongToStr(My_number, string); 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 } } //**********************************************************************
Attachments
Last edited: