Mithun_K_Das
Advanced Member level 3
- Joined
- Apr 24, 2010
- Messages
- 899
- Helped
- 24
- Reputation
- 48
- Reaction score
- 26
- Trophy points
- 1,318
- Location
- Dhaka, Bangladesh, Bangladesh
- Activity points
- 8,254
As PIC12F675 doesn't have more pins to I want to add a shift register to extend its outputs. I want to use 4094 8-bit shift register. I tried some programs but can't work. Can anyone help me in this case?
- - - Updated - - -
I did this program from this link with some modification. Its working good. But one problem is the Q0(PIN4) is always high.
Can you tell me where I did wrong?
Here is the Simulation image:
- - - Updated - - -
- - - Updated - - -
I did this program from this link with some modification. Its working good. But one problem is the Q0(PIN4) is always high.
Can you tell me where I did wrong?
Here is the Simulation image:
- - - Updated - - -
Code:
/********************************************************************************
Program for Shift register using to extend MCU's I/O
Program writteb by MKDas; Date: 26-Feb, 2013.
MCU: PIC12F675; X-Tal: 8M internal
********************************************************************************/
// PIN declaration
sbit Shift_E at GP0_bit;
sbit Shift_CLK at GP1_bit;
sbit Shift_D at GP2_bit;
sbit Shift_E_Dirrection at TRISIO0_bit;
sbit Shift_CLK_Dirrection at TRISIO1_bit;
sbit Shift_D_Dirrection at TRISIO2_bit;
// End of declearation
void WriteByteToShift(unsigned Byte)
{
unsigned char BitCount =0;
for(BitCount=0;BitCount<8;BitCount++)
{
Shift_D = (((Byte>>BitCount)&0x1)!=0);
Delay_us(10);
Shift_CLK = 1;
Delay_us(10);
Shift_CLK = 0;
Delay_us(10);
}
}
ToggleEpin()
{
Shift_E = 1;
Delay_us(100);
Shift_E = 0;
Delay_us(100);
}
void WriteDataToShift(unsigned Data)
{
WriteByteToShift(((Data&0xFF)>>4)|0x80); // write upper bits
ToggleEpin();
WriteByteToShift(((Data&0xFF))|0x80); // write lower bits
ToggleEpin();
}
int dis;
void main()
{
CMCON=0x07;// turn off comparator
ANSEL=0x07;// ADC configuration
OSCCAL = 0xFF;// internal X-Tal settings
TRISIO=0b00001000; // I/O settings
GPIO=0x00;
while (1)
{ // Endless loop
while(GP3_bit==1)
{
dis++;
WriteDataToShift(dis);
Delay_ms(1000);
break;
}
WriteDataToShift(0);
}// while
}// void