I'm trying to push myself off assembler and learn some C, but can't seem to get a working dump from this PISO shift chip. I tried my best to duplicate the order I used in the assembler version as far as the clock/latch activity goes, but I've obviously done something wrong. I've also rearranged the order to no avail, so I'm guessing the flaw is elsewhere.
The output on PORTB is basically nothing after the flashing intro lights.
Thanks!
- BTW, I'm running Hi-Tech 9.83 under MPLAB 8.92
- Code: Select all
#include <htc.h> //yeah, I probably don't need these ;)
#include <stdint.h>
#include <pic16f84a.h>
__CONFIG(FOSC_XT & CP_OFF & PWRTE_OFF & CP_OFF & WDTE_OFF);
#define _XTAL_FREQ 4000000
#define data RA2
#define latch RA0
#define clk RA1
unsigned char myByte; //should hold the returned 74HC165 data
unsigned char shiftin(void);
void twoflash(void) //just a flashing light routine
{ RB7 = 1;
__delay_ms(300);
RB7 = 0;
__delay_ms(300);
RB7 = 1;
__delay_ms(300);
RB7 = 0;
__delay_ms(300);
}
unsigned char shiftin()
{
unsigned char inByte = 0; //temp holder for the grabbed byte
unsigned int i = 0;
latch = 0; //drops to capture the register
latch = 1; //back to default
while(i < 8) {
//test the serial out
if(data && 1) // data is one
{ inByte <<= 1;
inByte += 1; } // rotate left and set bit 0
else //data is zero
inByte <<= 1; // rotate left, bit 0 defaults to 0
i++;
clk = 1; //pulse the clock high
clk = 0; //drop back to default
}
return inByte; // leave with the byte
}
void main()
{
TRISA = 0b11110000;
TRISB = 0b00000000;
PORTB = 0;
latch = 1;
clk = 0;
twoflash(); // just shows that the program started
while(1)
{
myByte = shiftin();
PORTB = myByte;
}
}