C Code Help

Status
Not open for further replies.

Suraj143

Active Member
Guys I need to load a 8 bit value to 74HC595 IC.Please see my code is ok?Its not working.

Code:
void load_595(short num){
short mask;
            for(mask=0b10000000;mask>0;mask=mask>>1){
            if ((mask & num)>0)  {
            sdata=1;
            clk_595();
            }
            else{
            sdata=0;
            clk_595();
            }
}
latch_595:
           slatch=1;
           delay_us(1);
           slatch=0;
}
 void clk_595(){
           sclock=1;
           delay_us(1);
           sclock=0;
           }

I use mikroC.The compilor generates such an asm code that I doubt.
It always set bit 7 of the mask register when I shift it right

Code:
//for(mask=0b10000000;mask>0;mask=mask>>1){
        RRF        load_595_mask_L0+0, 1
        BCF        load_595_mask_L0+0, 7
        BTFSC      load_595_mask_L0+0, 6
        BSF        load_595_mask_L0+0, 7
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…