Wednesday, October 7, 2020

Blinking the PIC16F887 in MikroC

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. 

  1. #define LED PORTD.RD0 // LED IS AT RD0
  2. #define rate 1000 // rate is 1000ms
  3.  
  4. void main() {
  5. LED=0; // CLEAR LED
  6. TRISD=0x00; // PORTD AS OUTPUT
  7. while (1)
  8. {
  9. LED=0; // LED OFF
  10. delay_ms(rate); // wait for 1000ms
  11. LED=1; // LED ON
  12. delay_ms(rate); // wait for 1000ms
  13. }
  14. }

The input parameter to the delay_ms() function is a unsigned long data type. However it is a constant rather than a variable.

Blinking the PIC16F887 in MikroC
Schematic Diagram


No comments:

Post a Comment

Labels

ADC (10) Analog (14) Arduino (12) Atmega16 (19) Audio (2) AVR (20) Charger (1) Cortex-M0 (1) Counter (10) CPLD (25) Digital I/O (22) Display (34) EEPROM (2) Environment Sensor (1) esp8266 (2) Experiment Board (10) I2C (4) Interrupt (7) LCD (1) LDmicro (29) measurement and instrumentation (7) Microchip Studio (3) MikroC (1) One-Shot (3) OpAmp (1) PCB (31) PIC16 Microcontrollers (16) PIC16F877A (2) PIC16F887 MikroC (22) PLC (35) PWM (11) Regulator (1) RTC (2) Sensor (8) Shift Registers (5) SPI (5) Timer (34) UART (2) ultra-sonic sensor (1) USB (1) VHDL (21) xc8 (1) XC95108 (9) XC9536 (15) XC9572 (1) Xilinx (23) Xilinx ISE (22)