This week I bought PIC12F683 (a very small pin count PIC microcontroller) from a local online electronic kits and parts store : www.evselectro.com. I ordered a small list of parts from this store on last saturday and to my surprise the parts I ordered were delivered to me at an additional cost of just RS200 delivery charges, at my home in Islamabad on Tuesday evening. The newly opened on-line store seems to have a very large stock of parts (if you compare it with other local on-line part suppliers in Pakistan such as www.digipak.org or electronicspk.com).
Pakistan have very few on-line electronic kits and parts stores and this addition of a new store is definitely a good news for all the enthusiasts belonging to my country.
Running PIC12F683 to blink an LED was relatively very easy task.
1. I just had to wire this small circuit (see figure 1) on a breadboard,
2. Created a PIC12F683 C project using MikroC IDE,
3. Edited configuration of microcontroller (see figure 2)
4. wrote a small program (see figure 3),
5. hooked up my home-brew PICKIT2 programmer and programmed hex file to this tiny 8 pin microcontroller using PICKIT2 progmming software.
And was able to see the LED blinking!
Figure-1:
PIC12F683 has two built-in oscillators.
1. 8.0MHz Oscillator
2. 32 KHz Oscillator
In this example I am using 8 Mhz internal oscillator. The 8 MHz internal oscillator can also be further divided using built-in post scaler by writing to ICRF[2:0] bits in OSCCON register.
The settings for running microcontroller by internal oscillator can be accessed in MikroC IDE by pressing CTRL+SHIFT+E. The first setting Oscillator [ Internal RC Clockout ] configures PIC12F683 microcontroller to run from 8 MHz internal oscillator and output divided by 4 clock (2 MHz in our case) at pin 3 of the microcontroller. You may also select Oscillator [ Internal RC No Clock ] in case if you dont want to output internal clock output. This way you can save one pin and can use it for your purposes.
Here is screen shot of settings (Figure 2):
The code in this project toggels LED at every 250msec. The first line configures oscillator postscaller to get 8 MHz from internal oscillator by not dividing the original 8MHz.
Here is the screen shot of code written for MikroC Pro Version 4.15:
Figure 3:
PIC12F683 PWM Example:
Here is another code sample for PWM example using PIC12F683. In this code the LED is connected at pin 5 (GP2/AN2/T0CKI/INT/COUT/CCP1 - PWM channel 1). The intensity of LED light in this example is increased as the variable "dc" is incremented, and after reaching maximum intensity it becomes zero and led turns off. So you keep observing led intensity ramping up and then becoming zero while this code runs forever.
The code uses MikroC library functions to initialize /set pwm frequency and set pwm duty cycle. MikroC is a great compiler to easily setup and run but in case of PWM peripherial, its functions do not utilize full functionality of pic microcontroller's pwm channel. The PWM1_Set_Duty() function takes 8 bit char value which it assigns to upper 8 bits of the pwm duty cycle register and compromises the full resolution of 10 bits.
Figure 4:
Pakistan have very few on-line electronic kits and parts stores and this addition of a new store is definitely a good news for all the enthusiasts belonging to my country.
Running PIC12F683 to blink an LED was relatively very easy task.
1. I just had to wire this small circuit (see figure 1) on a breadboard,
2. Created a PIC12F683 C project using MikroC IDE,
3. Edited configuration of microcontroller (see figure 2)
4. wrote a small program (see figure 3),
5. hooked up my home-brew PICKIT2 programmer and programmed hex file to this tiny 8 pin microcontroller using PICKIT2 progmming software.
And was able to see the LED blinking!
Figure-1:
PIC12F683 has two built-in oscillators.
1. 8.0MHz Oscillator
2. 32 KHz Oscillator
In this example I am using 8 Mhz internal oscillator. The 8 MHz internal oscillator can also be further divided using built-in post scaler by writing to ICRF[2:0] bits in OSCCON register.
The settings for running microcontroller by internal oscillator can be accessed in MikroC IDE by pressing CTRL+SHIFT+E. The first setting Oscillator [ Internal RC Clockout ] configures PIC12F683 microcontroller to run from 8 MHz internal oscillator and output divided by 4 clock (2 MHz in our case) at pin 3 of the microcontroller. You may also select Oscillator [ Internal RC No Clock ] in case if you dont want to output internal clock output. This way you can save one pin and can use it for your purposes.
Here is screen shot of settings (Figure 2):
The code in this project toggels LED at every 250msec. The first line configures oscillator postscaller to get 8 MHz from internal oscillator by not dividing the original 8MHz.
Here is the screen shot of code written for MikroC Pro Version 4.15:
Figure 3:
PIC12F683 PWM Example:
Here is another code sample for PWM example using PIC12F683. In this code the LED is connected at pin 5 (GP2/AN2/T0CKI/INT/COUT/CCP1 - PWM channel 1). The intensity of LED light in this example is increased as the variable "dc" is incremented, and after reaching maximum intensity it becomes zero and led turns off. So you keep observing led intensity ramping up and then becoming zero while this code runs forever.
The code uses MikroC library functions to initialize /set pwm frequency and set pwm duty cycle. MikroC is a great compiler to easily setup and run but in case of PWM peripherial, its functions do not utilize full functionality of pic microcontroller's pwm channel. The PWM1_Set_Duty() function takes 8 bit char value which it assigns to upper 8 bits of the pwm duty cycle register and compromises the full resolution of 10 bits.
Figure 4:
Nice beginner project, thanks.
ReplyDeleteIf you are looking for more PIC circuit ideas, look at:
www.artic-instruments.webs.com
Thanks for sharing.Its is very helpful for us.If you university student or you are working On FYA or DIY project.Here you can buy all electronic components in Pakistan.
ReplyDeleteRespect and I have a tremendous provide: Where Do You Get The Money To Renovate A House hgtv home renovation
ReplyDelete