Starting to program a micro-controller is usually writing a code with blinking an LED to make sure that the introductory coding works correctly. Most of embedded C compiler makes a ready to use examples include all the features of their compiler and the target MCU.
However I make an easy beginning to code the PIC16F887 8-bit MCU with MikroC for PIC. A free version of this compiler offers a free firmware building of the coding size that does not exceed 2 Kb of MCU program memory.
Using PORTD of the PIC16F887, the CPU regularly toggle pin RD0 for every one second. The delay_ms() function of the MikroC create an acceptable delay time in milli-seconds.
#define LED PORTD.RD0 // LED IS AT RD0 #define rate 1000 // rate is 1000ms void main() { LED=0; // CLEAR LED TRISD=0x00; // PORTD AS OUTPUT while (1) { LED=0; // LED OFF delay_ms(rate); // wait for 1000ms LED=1; // LED ON delay_ms(rate); // wait for 1000ms } }
The input parameter to the delay_ms() function is a unsigned long data type. However it is a constant rather than a variable.
Schematic Diagram |
No comments:
Post a Comment