gabeNC
Member
Howdy gents,
Had some time off during Christmas and thought I would *finally* use some shift registers. I have the 595 wired to a LED bar graph and it flashes faintly, I can just barely see it, even when passing all zero's or 0b10101010 it seems to be all the segments. I'm sure the solution is something easy (and stupid) but the it has eluded me of late.
Using a 18f4620 and ST M74HC595B1.
thanks!
Here's a Saleae screen shot of the 595 IC.
Had some time off during Christmas and thought I would *finally* use some shift registers. I have the 595 wired to a LED bar graph and it flashes faintly, I can just barely see it, even when passing all zero's or 0b10101010 it seems to be all the segments. I'm sure the solution is something easy (and stupid) but the it has eluded me of late.
Using a 18f4620 and ST M74HC595B1.
thanks!
Code:
#include <p18f4620.h>
#include <delays.h>
#include <timers.h>
#pragma config OSC = INTIO67 // Internal oscillator, OSC1 & OSC2 are IO
#pragma config FCMEN = OFF // Fail-safe clock monitor off
#pragma config IESO = OFF // Int-Ext Osc switchover disabled
#pragma config PWRT = OFF // Power-up timer disabled
#pragma config BOREN = OFF // Brown-out reset disabled
#pragma config BORV = 0 // Brown-out voltage maximum
#pragma config WDT = OFF // Disable hardware watch-dog timer control
#pragma config MCLRE = ON // MCLR enabled
#pragma config LPT1OSC = ON // T1 Oscillator enabled
#pragma config PBADEN = OFF // Port B A/D disabled digital on reset
#pragma config CCP2MX = PORTBE // CCP2 MUX
#pragma config STVREN = ON // Stack overflow reset enabled
#pragma config LVP = OFF // Low voltage ICSP disabled
#pragma config XINST = OFF // Enable extended instruction set
#pragma config DEBUG = OFF // Background debugger enabled
#define ClockPin PORTAbits.RA0 // SCK Clock Input
#define DataPin PORTAbits.RA1 // SI Serial Data Input
#define LatchPin PORTAbits.RA2 // RCK Latch
#define OutputEnable PORTAbits.RA3 // G
/*
PIC Pin 595 Data sheet pin / desc
===============================================
RA0 SCK Shift Register Clock Input
RA1 SI Serial Data Input
RA2 RCK Storage Register Clock (latch)
RA3 G Output Enable
*/
void ShiftOut(unsigned short long dat){
unsigned char i;
LatchPin=0;
OutputEnable=0;
for(i=0;i<8;i++){
ClockPin = 1;
DataPin=dat & 1;
Nop();
dat>>=1;
ClockPin = 0;
}
LatchPin=1;
OutputEnable=1;
}
// a debug indicator
void FlashRA4(char time){
LATAbits.LATA4 = 1;
Delay10KTCYx(time);
LATAbits.LATA4 = 0;
Delay10KTCYx(time);
}
void main (void)
{
OSCCON = 0x62; // Int Osc, 4Mhz
while(!OSCCONbits.IOFS); // Wait for osc to be stable
TRISA = 0;
FlashRA4(50);
while(1)
{
FlashRA4(25);
ShiftOut(0b00000000);
Delay10KTCYx(100);
ShiftOut(0b01010101);
Delay10KTCYx(100);
ShiftOut(0b11111111);
Delay10KTCYx(100);
}
}