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.

[SOLVED] Interfacing Shift Register to extend outputs of PIC12F675

Status
Not open for further replies.

Mithun_K_Das

Advanced Member level 3
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
Visit site
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:
sdfsdfs.png

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

Ahh!!!!!!!!!!!! Thanks ***!!!!!!!!. I've made it!!!!

Here is the corrected code!!!
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 GP4_bit;
sbit Shift_CLK at GP2_bit;
sbit Shift_D   at GP5_bit;

sbit Shift_E_Dirrection   at TRISIO4_bit;
sbit Shift_CLK_Dirrection at TRISIO2_bit;
sbit Shift_D_Dirrection   at TRISIO5_bit;
// End of declearation

void WriteByteToShift(unsigned Byte)
{
 unsigned char BitCount = 0;
 for(BitCount=0;BitCount<8;BitCount++)
 {
  Shift_D = (((Byte>>BitCount)&0x01)!=0);
  Shift_CLK = 1;
  Delay_us(10);
  Shift_CLK = 0;
  Delay_us(10);
 }
}
ToggleEpin()
{
 Shift_E = 1;
 Delay_us(10);
 Shift_E = 0;
 Delay_us(10);
}


void WriteDataToShift(unsigned Data)
{
 WriteByteToShift(((Data&0xF0)>>4)|0x00); // write upper bits
 ToggleEpin();
 WriteByteToShift(((Data&0xFF))|0x00); // write lower bits
 ToggleEpin();
}

int dis;
void main() 
{
 CMCON=0x07;// turn off comparator
 ANSEL=0x07;// ADC configuration
 OSCCAL = 0xFF;// internal X-Tal settings
 TRISIO=0b00001011; // I/O settings
 GPIO=0x00;
 while (1)
  {                            // Endless loop
   while(GP3_bit==1)
   {
    dis++;
    WriteDataToShift(dis);
    Delay_ms(100);
    break;
   }
   WriteDataToShift(0b00000000);
  }// while
}// void
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top