Tuesday, October 23, 2012

Scroll text on 8x8 LED Matrix Display using PIC18F4550 and MikroC compiler

Lights and LEDs always fascinate me. In this experiment with 8x8 led matrix display, I have interfaced an 8x8 led matrix without using any external buffer IC to the PIC microcontroller. This saves cost and wiring hassle as well as makes the design simple. PIC microcontrollers can sink and source 20mA through its pins. That's what made me think of eleminating external buffer IC which people normally use when they use other microcontrollers which can not sink and source at 20mA directly.


In this experiment I have used PIC18F4550 because it was already present in my component box. You may replace PIC18F4550 with other PIC mikrocontrollers. The 8x8 LED matrix displays have total of 64 leds which are wired in 8 columns and 8 rows (Please see figure 1). The 8x8 LED Dot matrix display that I used was 2.3" GMC2X88C. I had further made an excel sheet to understand wiring inside this 8x8 (Please see figure 2). Sometimes when you buy an 8x8 led matrix you may not know its manufacture part number (as the part number printed on these matrix sometimes are not searchable and you cant find the datasheet), therefore you may need to find yourself the pin-outs of your led matrix. And that's what I did, I used multimeter to figure out cathode and anodes of the display and later found that my display closely matches Fairchild's Part Number GMC2X88C.

Video




Figure 1:


Figure 2 - 8x8 Led Matrix Pinouts explained in detail:



Schematics:
















Pdf copy of the Schematics can be downloaded from here:
8x8_Led_Matrix_Schematics.pdf

Source Code:
C Source Code zip file can be downloaded from here:
LED_Matrix_8x8_timer.zip

The Oscillator settings for this project can be copied from following snapshot of MikroC compiler. PIC18F4550 in this example the PIC microconteoller is running from internal 8.000MHz oscillator. The dialog box can be accessed by pressing Ctrl+Shift+E


Datasheets:
1. GMC2X88C - 8x8 dot matrix led display:
http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/GMA2288C,GMC2288C.pdf
2. PIC18F4550 - PIC 18F series microcontroller from Microchip:


Thursday, October 11, 2012

Experiment with an 8 pin PIC12F683 microcontroller using MikroC

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: