Blackfin:
Give this a try. It's supposed to count your digits up from 0-9 and back to zero again, once per second. It should also toggle the DP every 300mS.
Compiles, not tested...
const uint8_t LATCH=12;
const uint8_t CLOCK=11;
const uint8_t DATA=14;
const uint8_t dp = LED_BUILTIN;
#define heartbeat_on PORTB = PORTB | B00100000
#define heartbeat_off PORTB = PORTB & B11011111
#define LATCH_ON PORTC = PORTC | B00001000
#define LATCH_OFF PORTC = PORTC & B11110111
#define CLOCK_ON PORTB = PORTB | B00010000
#define CLOCK_OFF PORTB = PORTB & B11101111
#define DATA_ON PORTB = PORTB | B00000001
#define DATA_OFF PORTB = PORTB & B11111110
#define NUMB0_SEG B00111111
#define NUMB1_SEG B00000110
#define NUMB2_SEG B01011011
#define NUMB3_SEG B01001111
#define NUMB4_SEG B01100110
#define NUMB5_SEG B01101101
#define NUMB6_SEG B01111101
#define NUMB7_SEG B00000111
#define NUMB8_SEG B01111111
#define NUMB9_SEG B01100111
uint8_t
grNumMasks[] =
{
NUMB0_SEG, NUMB1_SEG, NUMB2_SEG, NUMB3_SEG, NUMB4_SEG,
NUMB5_SEG, NUMB6_SEG, NUMB7_SEG, NUMB8_SEG, NUMB9_SEG
};
bool
bDraw = false,
ledState = false;
uint32_t
timeDP=0,
timeCount=0;
uint8_t
count = 0;
uint32_t
timeNow_mS = millis();
void setup()
{
// set the digital pin as output:
DDRB |= B00100000;
DDRC |= LATCH_ON;
DDRB |= DATA_ON;
DDRB |= CLOCK_ON;
pinMode( dp, OUTPUT ); //LED pin
CLOCK_OFF;
DATA_OFF;
LATCH_OFF;
bDraw = true; //force a digit draw right away
Serial.begin(9600);
}//setup;
void loop()
{
//count up digits once per second
if( (timeNow_mS - timeCount) >= 1000ul )
{
timeCount = timeNow_mS;
count++; //bump the digit to show
if( count == 10 ) //if we roll over past 9, go back to zero
count = 0;
bDraw = true; //force a digit update
}//if
//flash the LED every 300mS
if( (timeNow_mS - timeDP) >= 300ul )
{
timeDP = timeNow_mS;
ledState ^= true; //^ operator is exclusive OR. this toggles the state of teh ledState boolean
digitalWrite( dp, ledState ); //reflect state of DP on built-in LED
bDraw = true; //indicate we need to update the digit
}//if
//if a digit/DP update is needed, "draw" it
if( bDraw == true )
{
ShiftNumber( count, ledState ); //send digit and state of DP to draw
bDraw = false; //then clear the draw flag
}//if
}//loop
void ShiftNumber( uint8_t num, bool bDP )
{
uint8_t
mask,
shiftval;
//make sure the # to be drawn is within bounds
if( num > 9 )
return;
//get the pattern of bits to send into shiftval
shiftval = grNumMasks[num];
//the msb of shiftval is the DP; if the DP flag is set, turn this bit on
shiftval |= (bDP == true) ? 0x80:0x00;
//we look at each bit, starting from the msb
mask = 0x80;
do
{
//if the bit is set in the mask, we set data
if( shiftval & mask )
DATA_ON;
else
DATA_OFF;
//toggle clock high then low
CLOCK_ON;
CLOCK_OFF;
//move the mask one bit to the right (so 80 40 20 10 08 04 02 01 -> 00 (00 indicates we're done all bits)
mask >>= 1;
}while( mask );
//once all are shifted out, toggle the storage reg latch
LATCH_ON;
LATCH_OFF;
}//ShiftNumber
i tried uploading this code but all it does is shows a 0 on the 7 seg display and nothing is flashing?