/********************************************************************************
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