Sponge_Bob,
Tsk, tsk - you're lucky I'm in a generous mode tonight.
Alright, first thing to do is open the PBP INC file for the 16F628A and comment out the config line. Assuming you're using Windows and have everything installed in the default locations go to: C:\pbp and open the file named 16F628A.INC. Place a semicolon in front of the line starting with: __config and save the file.
I've included a schematic to try out. And here's some code to try:
Code:
INCLUDE "modedefs.bas"
asm
__config _INTOSC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF & _BOREN_OFF & _PWRTE_ON
endasm
DEFINE OSC 4 ' Tell the program the oscillator is running at 4 MHz
CMCON.0 = 1 ' Turn off comparators
CMCON.1 = 1 ' Turn off comparators
CMCON.2 = 1 ' Turn off comparators
VRCON.6 = 0 ' Disconnect Vref from RA2
VRCON.7 = 0 ' Vref is powered off
TRISA = %11111111 ' Make all port a pins inputs
TRISB = %11101000 ' Make port b pins 0-2 & 4 outputs and the rest as inputs
PORTA = $00 ' Set all port a pins to low
PORTB = $00 ' Set all port b pins to low
SPI VAR PORTB.2 ' Serial input to STP16DP05
CLK VAR PORTB.1 ' Clock input to STP16DP05
LE VAR PORTB.0 ' Enable pin for STP16DP05
OE VAR PORTB.4 ' PWM / ON & OFF for LEDs
LED_value VAR word ' Variable used to send data to STP16DP05
flip VAR bit ' Used to determine which direction to scroll LEDs
LOW OE ' Turn on LEDs
LED_value = $FFFF ' Set LED value equal to $FFFF to turn on all the LEDs
'***********************************************************************************************
Test: ' Test Routine - Flash all LEDs once
SHIFTOUT SDI, CLK, 1, [LED_value\16] ' Send data to STP16DP05
HIGH LE ' Enable the STP16DP05
LOW LE ' Disable the STP16DP05
PAUSE 500 ' Wait for half a second
LED_value = $0000 ' Set LED value equal to zero to turn off all the LEDs
SHIFTOUT SDI, CLK, 1, [LED_value\16] ' Send data to STP16DP05
HIGH LE ' Enable the STP16DP05
LOW LE ' Disable the STP16DP05
PAUSE 500 ' Wait for half a second
'***********************************************************************************************
' To do the same thing without sending data to STP16DP05 multiple times, try this:
LED_value = $FFFF ' Set LED value equal to $FFFF to turn on all the LEDs
SHIFTOUT SDI, CLK, 1, [LED_value\16] ' Send data to STP16DP05
HIGH LE ' Enable the STP16DP05
LOW LE ' Disable the STP16DP05
PAUSE 500 ' Wait for half a second
HIGH OE ' Turn off all LEDs regards of state of latches on STP16DP05
PAUSE 500 ' Wait for half a second
'***********************************************************************************************
LOW OE ' Turn on all LEDs where latches are enabled
LED_Value = $0001 ' Set LED value to %0000000000000001 to turn on first LED
'***********************************************************************************************
Main: ' Main Routine - Simple Knight Rider Effect
SHIFTOUT SDI, CLK, 1, [LED_value\16] ' Send data to STP16DP05
HIGH LE ' Enable the STP16DP05
LOW LE ' Disable the STP16DP05
IF LED_value = $8000 THEN flip = 1 ' If LED value is equal to %1000000000000000, then set flip equal to one
IF LED_value = $0001 THEN flip = 0 ' If LED value is equal to %0000000000000001, then set flip equal to zero
IF flip = 0 THEN ' If flip is equal to zero, then
LED_value = LED_value << 1 ' Shift LED value to left by one
ELSE ' If flip is not equal to zero, then
LED_value >> 1 ' Shift LED value to left by one
ENDIF ' End if statement
PAUSE 500 ' Wait for half a second
GOTO Main ' Go to Main routine
'***********************************************************************************************
END ' End program should it run awry
Now, please note that I haven't tried this code out, but hopefully it's enough to get you started. Let me know if you have any problems and good luck!
Bookmarks