PIC - driving a shift register in C

robz

New Member
Hello people,

got a question for one of my projects. I'm using the PIC18F87J11 for a project and i need to make a shift register. I'll use 3 "normal" I/O lines for creating one. First line for data, second for a clock and third for enable. The lines are directly connected to a CPLD (simplified FPGA), which implemeted a shift register an that part is already working.

Now i'll have to write code in C (beacause my hole project is in C) to create those 3 lines which will drive the shift register (in the CPLD).

I can create clock signals by setting the output high, wait for a while, setting the output low and soo on. But is there a smarter way to do it?

And how can i create a 8 bit serial bit stream? maybe with some shift left/right instructions?

Please help me by solving this problem. Thank You !
 
here is the sample where 74595 is used (shift register with latched output)

Code:
#define S_CLOCK PORTD.F3
#define S_CLEAR PORTD.F1
#define S_DATA  PORTD.F0
#define S_STORE PORTD.F2

#define STORE S_STORE =1; S_STORE =0

void SEND(unsigned short x){
  S_CLOCK = 0;
  S_DATA = x;
  asm{
    nop
  }
  S_CLOCK = 1;
  S_DATA = 0;
}

void main(){
  unsigned short h,l;
  unsigned short i;
  
  TRISD = 0;
  PORTD = 0;

  STORE;
  S_CLOCK = 1;
  S_CLEAR = 1;
  

  
  h = 0b10101101;
  l = 0b11011001;

  //send 2 bytes
  for (i=0;i<8;i++){
     SEND(l & 0x01);
     l = l >> 1;
  }
  for (i=0;i<8;i++){
     SEND(h & 0x01);
     h = h >> 1;
  }
  STORE;
}

If you use "unlatched" shift registers, then you do not need S_STORE line nor STORE define as all changes are immediate
 
100 shift registers?? You mean 100 seven segment displays? For what purpose..

I have a simple 8 shift register hook up to a pic16f877a! Using 74ls323 shift registers... But the code ois interrupt driven..
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…