An Interrupt Using an Input Pin on a PIC16F690 CCS C

This is just a short post on how I used an interrupt to make my Pickit 2 cycle through the LEDs. This is a very simple program, and sadly I tried this once before and it didn’t work. I did a little research and found that I didn’t enable the correct interrupts.  This experiment is just one of a few that may need to take place to design my POV for my CCS compiler. I have a Picaxe POV, but I want high brightness LEDs and it to be in C. I like projects, and this one (POV)  is going to be a little bit different than the Picaxe one. Enjoy the journey in developing my next toy.
Continue reading

Part 2: Going to Sleep(); An Interrupt Using an Input Pin on a PIC16F690 CCS C

This is part two of the POV design. I added a sleep function to this program. It counts up to 14. Once it hits 15 it goes to sleep, only to be awakened by MCLR and starting from the beginning of the program. Please enjoy.

#include <16f690.h>
#fuses intrc_io,mclr,put,nobrownout,nowdt
#use delay(clock=31000) //clock set to oscillator frequency
int count=0;

#INT_RB //this is the interrupt
void interruptMe(void) { count++; delay_ms(250); }

void main(void)
{
setup_oscillator(osc_31khz); //This uses less current than 4MHz
enable_interrupts(INT_RB7); //a change on RB7 triggers interrupt
enable_interrupts(GLOBAL);

while (1)   {  output_c(count);
if (count==0x0f)
{
output_a(0×00); output_b(0×00); output_c(0×00); //set all outputs to ground
sleep(); //should only wake up after MCLR
}  }  }

Using the PIC16F690′s (and others’) Internal Timers to Keep Time

This one is so easy a kid could do it. Actually, once you see how easy it is  to keep a somewhat accurate count with an internal oscillator, you’ll probably wonder why I ever spent $7 on a DS1305. If you just want a simple, somewhat inaccurate timepiece, neglecting to use an RTC can make things really simple. The $7 for a real RTC is worth it :).

The first experiment is to check if our interrupts work. We are using timer 2 to generate an interrupt every millisecond. Inside the interrupt we have a 16-bit variable counting to 1000, and then it increments the seconds variable. Then, when seconds hit ten, it starts the loop back at 0. I then output the seconds byte to port C on the Pickit 2. The LEDs show a binary count of the seconds. Tune in for the next installment. I’ll have a clock with four blue 7-segment LEDs that I’m stealing from my first clock project that kept time right, but nothing else.

#include <16f690.h>
#fuses intrc_io,nowdt,nomclr,noborownout,put
int seconds=0; int16 milliseconds=0;

#INT_TIMER2
void incrementSeconds()
{
milliseconds++;
if (milliseconds==1000)
{milliseconds==0; seconds++}
if (seconds==10) seconds=0;
}

void main(void)
{
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
setup_timer_2(timer_2_div_by_1,0×64,10); //1ms interrupt
set_timer2(0);
while (1)
{ output_c(seconds); } //binary count of seconds
}

CCS C and Microchip PWM – Pulse Width Modulation

Tonight I was wondering why my PWM wasn’t working. It took me a while to figure it out, but I have it working.

Start with your C file with your normal #include and #fuses. Inside your main function you’ll use 4 built in functions and the super loop While statement. That is it! I wired a high brightness LED to pin 5 of the PIC16F690 on the Pickit 2.
Continue reading

Microcontrollers: Stamp, Picaxe, Microchip, Atmel? Assembly, Basic, C? Which way to go?

I have started getting into some different types of programming for microcontrollers lately. I have wanted to learn C for Microchip’s line of microcontrollers, and now that I have begun I have found it to be relatively expensive. There are pros and cons for every platform, so I am going to blog on my experience so far.
Continue reading