C8051F340 flashing led example

This LED flashing example was written for a C8051F340 dev board connected to a DVK501 board by Waveshare, the basic example will simply toggle PORT1 high and low

This is the DVK501 board – there are 8 LEDs on the board
AliExpress.com Product – DVK501 MCU PCF8563 DS18B20 MAX3232 PS/2 MAX485 LED Expansion Development Board

This is the development board I used
AliExpress.com Product – free shipping C8051 C8051F350 development board 51 development board

Schematic

Code

This was written in Keil uVision

[codesyntax lang=”c”]

#include <c8051f340.h>                 // SFR declarations


//-----------------------------------------------------------------------------
// Function Prototypes
//-----------------------------------------------------------------------------

void OSCILLATOR_Init (void);           
void PORT_Init (void);
void delay(unsigned int t);

//-----------------------------------------------------------------------------
// main() Routine
//-----------------------------------------------------------------------------

void main (void)
{
   PCA0MD &= ~0x40;                    // WDTE = 0 (clear watchdog timer
                                       // enable)

   PORT_Init();                        // Initialize Port I/O
   OSCILLATOR_Init ();                 // Initialize Oscillator
  
   while (1)
   {

         P1 = 0x00;                     // Turn on LED
				 delay(1000);
         P1 = 0xFF;                     // Else, turn it off
         delay(1000);             

   }                                   
}                                     



//-----------------------------------------------------------------------------
// OSCILLATOR_Init
//-----------------------------------------------------------------------------

void OSCILLATOR_Init (void)
{
   OSCICN |= 0x03;                     // Configure internal oscillator for
                                       // its maximum frequency (24.5 Mhz)
}

//-----------------------------------------------------------------------------
// PORT_Init
//-----------------------------------------------------------------------------
void PORT_Init (void)
{
   P1MDIN = 0xFF;
	 P1MDOUT = 0xFF;                     // enable LEDs as push-pull outputs
   XBR1    = 0x40;                    // Enable crossbar and enable                                     // weak pull-ups
}


//-----------------------------------------------------------------------------
// Delay
//-----------------------------------------------------------------------------
 void delay(unsigned int t)
{
    unsigned int i,j;
    for(i=0;i<t;i++)
        for(j=0;j<250;j++);
}

[/codesyntax]

Links

Related posts

8051 and RGB led example using the SiLabs IDE

8051 7 Segment display program written in Basic

8051 and 7 segment displays