Help pic16f877a with 74HC595 problem

Status
Not open for further replies.

Programmer.C

Junior Member level 1
Joined
May 6, 2006
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,414
hi all

I have written the code blew in mikroBasic Pro to drive 4 seven segment
& it works well on Proteus the purpose of code is to make a counter from 0 to 9 on the 4 seven segment
but when i apply it on the real world it does not give me the expected result
also the seven segment are flickering all the time
note : My hardware is connected well & fully tested

is that code right ?

Code:
program HC595

' Declarations section 
                                  '( 0  , 1  , 2  , 3  , 4  , 5  , 6  , 7  , 8  , 9  )
  const AnodeNumbers as byte[10] = (0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90)
  
  dim Datax as sbit at RB0_bit    'Data Input
  dim Clk as sbit at RB1_bit    'clock
  dim Latch as sbit at RB2_bit    'Latch
  dim iLoop as byte

sub procedure ClockPuls()
    Clk = 1
    delay_us(5)
    Clk = 0
end sub

sub procedure LatchPuls()
    Latch = 1
    delay_us(5)
    Latch = 0
end sub

sub procedure ShiftOut(dim dgt as byte)

  dim i as byte
  dim RegCnt as byte

 for RegCnt = 0 to 3'shift registers count (4 shift registers)
 
'-----------------------------------------------
    for i = 0 to 7
 
      if ((dgt<<i) AND 0x80)  then
          Datax = 1
      else
          Datax = 0
      end if

      ClockPuls

   next i

   LatchPuls
   
'-----------------------------------------------
 next RegCnt

end sub

main:
'   Main program 
  TRISB = 0
  portb = 0

  while 1

       ShiftOut(%11111111)
       Delay_Ms(5000)

       for iLoop = 0 to 9
            ShiftOut(AnodeNumbers[iLoop])
            Delay_Ms(5000)
       next iLoop

  wend

end.
 

okay anyway i have exceeded this point by rewriting the code in mikroC & it works well
But i have another problem the program works some times well & gives me the expected results but also some times it gives me unexpected results
i think there's (data loss on the serial bus) AND i don't what can i do & now this's my new code in mikroC

NOTE: the AnodeNumbers array depends on my new connection with the 7 segment & it's also tested & works well

Code:
const unsigned char AnodeNumbers[10] = {0x4,0x1F,0x88,0xA,0x13,0x22,0x20,0xF,0x0,0x2};  //Mohd Oraby Serial Seven Segment Anode Numbers For 1" B-C     4 Digits

sbit latch at RB1_bit;
sbit clock at RB0_bit;
sbit data_bit at RB3_bit;
sbit latch_Direction at TRISB1_bit;
sbit clock_Direction at TRISB0_bit;
sbit data_bit_Direction at TRISB3_bit;

/*-----------------------------------------------------------------------------*/

void send_data(unsigned char Digit);
void ZeroLatches(unsigned char LatchesCount);

/*-----------------------------------------------------------------------------*/
void main()
{
     unsigned char bLoop;
     latch_Direction=0;
     clock_Direction=0;
     data_bit_Direction=0;

     while(1)
     {
         ZeroLatches(4);
         Delay_ms(5000);

         for(bLoop=0;bLoop<10;bLoop++)
         {
           send_data(AnodeNumbers[bLoop]);
           Delay_ms(3000);
         }

     }
          
}
/*-----------------------------------------------------------------------------*/
void send_data(unsigned char Digit)
{
   unsigned char i;
   unsigned char cr;//shift registers count
   unsigned char db;

   for (cr=0;cr<4;cr++)
   {

     latch=0;
     clock=0;
     
     for(i=0;i<8;i++)
     {

       db=Digit>>i;
       
       if(db&1)
           data_bit=1;
       else
           data_bit=0;

       asm nop;
       
       clock=1;
       clock=0;

     }

        latch=1;
   }
   
}
/*-----------------------------------------------------------------------------*/
void ZeroLatches(unsigned char LatchesCount)
{
     unsigned char i;
     unsigned char j;
     
     for(i=0;i<LatchesCount;i++)
     {
         latch=0;
         for(j=0;j<8;j++)
         {
              data_bit=1;
              clock=1;
              clock=0;
         }
         latch=1;
     }
}
/*-----------------------------------------------------------------------------*/
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…