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
This is the development board I used
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