Software/Hardware used to work with Microchip PICs Testing Pic code to generate PWM signal
2007 17 Nov

Just made some tests to see how CCSInfo Compiler works! I’m really impressed! Very simple and easy!

For this test I’ve used Microchip PIC 16F628A working with an external 4MHz resonator and 1 led connected to the RB0 (pin6) - also requires one 1KOhm pull-up resistor to the led and the MCLR resistor to VCC.

Led Blink Test

  1. #include <16F628A.h>
  2. #use delay(clock=4000000)
  3. #fuses NOWDT, HS, PUT, NOPROTECT, BROWNOUT, MCLR, NOLVP, NOCPD
  4. //————————————————————————————————————————————————————————————
  5. void main(void)
  6. {
  7.   delay_ms(100); // power up delay
  8.  
  9.   setup_comparator(NC_NC_NC_NC);
  10.   setup_vref(FALSE);
  11.   set_tris_b(0b11111110);
  12.  
  13.   while( TRUE )
  14.   {
  15.     output_low(PIN_B0);
  16.     delay_ms(500);
  17.     output_high(PIN_B0);
  18.     delay_ms(500);
  19.   }
  20. }
  21. //————————————————————————————————————————————————————————————

Timer 0 Interrupt routine

  1. #include <16F628A.h>
  2. #use delay(clock=4000000)
  3. #fuses NOWDT, HS, PUT, NOPROTECT, BROWNOUT, MCLR, NOLVP, NOCPD
  4. //————————————————————————————————————————————————————————————
  5. // timer0 will interrupt every 4ms and call clock_isr()
  6. //————————————————————————————————————————————————————————————
  7. #INT_RTCC
  8. clock_isr()
  9. {
  10.   output_high(PIN_B0);
  11.   delay_us(5);
  12.   output_low(PIN_B0);
  13. }
  14. //————————————————————————————————————————————————————————————
  15. void main(void)
  16. {
  17.   delay_ms(100); // power up delay
  18.  
  19.   setup_comparator(NC_NC_NC_NC);
  20.   setup_vref(FALSE);
  21.   set_tris_b(0b11110000);
  22.  
  23.   setup_timer_0(RTCC_INTERNAL|RTCC_8_BIT|RTCC_DIV_16);
  24.   enable_interrupts(INT_RTCC);
  25.   enable_interrupts(GLOBAL);
  26.  
  27.   while(TRUE) ;
  28. }
  29. //————————————————————————————————————————————————————————————

Leave a Reply