Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Need some help when doing adder with AT89S52

Status
Not open for further replies.

gakko

Newbie level 6
Joined
Jun 6, 2013
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,363
I have do a adder have three button
it is reset, up, down respectively


It have some display error and plz help me

Code:
     sbit reset = P1^4;
     sbit up = P1^5;
     sbit down = P1^6;     


     unsigned char CA_Digits[] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E};
     unsigned int count = 0; 
     unsigned int a, b, c, d;
     
     P0 = 0x00;
     P1 = 0xFF;
     P2 = 0x00;
     
     while(1){

	if(P1^4==0);
	count = 0;
	if(P1^5== 0);
	count = count+1;
	if(P1^6 == 0);
	count = count-1;

          
          if(count <= 16){
                a = count;
                P2 = 0xFE;
                P0 = CA_Digits[a];
                delay();
                P2 = 0xFC;
                P0 = CA_Digits[0];
                delay();
                P2 = 0xF8;
                P0 = CA_Digits[0];
                delay();
                P2 = 0xF0;
                P0 = CA_Digits[0];
                delay();
          }
          
          if((count > 16) && (count <= 255)){
                a = count/16;
                b = count%16;
                P2 = 0xFE;
                P0 = CA_Digits[b];
                delay();
                P2 = 0xFC;
                P0 = CA_Digits[a];
                delay();
                P2 = 0xF8;
                P0 = CA_Digits[0];
                delay();
                P2 = 0xF0;
                P0 = CA_Digits[0];
                delay();
          }
          if((count > 255) && (count <= 4095)){
                a = count/255;
                b = (count/16)%16;
                c = count%16;
                P2 = 0xFE;
                P0 = CA_Digits[c];
                delay();
                P2 = 0xFC;
                P0 = CA_Digits[b];
                delay();
                P2 = 0xF8;
                P0 = CA_Digits[a];
                delay();
                P2 = 0xF0;
                P0 = CA_Digits[0];
                delay();
          }
          if((count > 4095) && (count <= 65535)){
                a = count/4095;
                b = (count/255)%16;
                c = (count/16)%16;
                d = count%16;
                P2 = 0xFE;
                P0 = CA_Digits[d];
                delay();
                P2 = 0xFC;
                P0 = CA_Digits[c];
                delay();
                P2 = 0xF8;
                P0 = CA_Digits[b];
                delay();
                P2 = 0xF0;
                P0 = CA_Digits[a];
                delay();
          }

     }
 
Last edited:

Error in your program..
Which micro controller you are using..hardware circuit..compiler etc...
Provide detailed explanation
 

I use the device is AT89S52
and it connect to 8 digits 7-segment display board
Also, AT89S52 connect to 9 button
one of it is stop other 8button and other 8button is P1 port
 

That code is written by me. You have modified it. It is for Common Anode display. It is for 4 digits and not 8 digits. It is to count and display 0 to 9999. What is your actual problem?
 

Well
when I write it in IC and connect to 7-segment display
then
i contral it with the button "+" "-" "reset"
it can not display well

In fact
when I press the button "+"
it will not display the number "1"
and it will display the random

- - - Updated - - -

I check the code and I did not find the error in program
however
I guess that I have write the display code error and I need some help

- - - Updated - - -

also I have some question
when P2 is 0x00 in start time
when I want to display 1 digits ( XXXX XXX0)
my P2 is 0x01 or 0xFE?
 

Try this code.

92488d1371531920-pic18f458_7seg.png
 

Attachments

  • 18F458_7Seg.rar
    129.1 KB · Views: 80
  • PIC18F458_7Seg.png
    PIC18F458_7Seg.png
    37.7 KB · Views: 99

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top