Friday, February 27, 2009
Tuesday, February 24, 2009
- A PIC microcontroller (16F886 seems like a good choice; a 12F683 can also be used).
- A 32.768 kHz crystal for timing (can be used as the primary clock source as well as timer clock source for the PIC).
- A display. For this purpose, an LED Matrix display or LED 7 segment display can be used. A very low power static LCD can also be used if low power consumption is part of the design goal.
- Shift registers can be used to drive the LED displays.
- Optionally, a system to synchronize to local low-frequency radio time signals can be added.
- A light level sensor can be used to automatically adjust LED brightness based on ambient light levels. Should be dim during the night and bright during the day. (Possible use for a photoresistor hooked up to the ADC on the PIC?)
- Include a user-programmable alarm.
- Include a calendar.
Monday, February 23, 2009
Sunday, February 22, 2009
A multivibrator is an electronic circuit used to implement a variety of simple two-state systems such as oscillators, timers and flip-flops. It is characterized by two amplifying devices (transistors, electron tubes or other devices) cross-coupled by resistors and capacitors. The most common form is the astable or oscillating type, which generates a square wave—the high level of harmonics in its output is what gives the multivibrator its common name.http://en.wikipedia.org/wiki/Multivibrator Can be used to build oscillators, touch switches, flip flops and so on.
Friday, February 20, 2009
Step 1: Send the Command
To define your own custom characters, you simply write to the character RAM. To do this, simply send the command (0x40 + address). The address can be anywhere from 0 - 63 as there are 64 bytes available for use. To start out, simply set the address to zero. So, send the instruction (0x40). I have my code set up like this:
send_cmd(0x40 + 0);
Step 2: Send the Data
You are now ready to start sending data to the LCD module to define your own characters. Each of the LCD blocks is composed of 5x8 pixels. Each row of pixels, top to bottom, represents one byte. Since each row only has 5 pixels, only the lower 5 bits of each byte you send will be considered by the LCD module. So, to start defining a character like the one shown here, you will need to now send the following data like this:
The character RAM pointer will auto-incriment so you don't have to keep setting the address. Just send the data. The above 8 bytes define the first character. To define another character, just directly send another 8 bytes representing your second character.
Step 3: Use Your Characters
To use your freshly-created custom characters, all you have to do now is set the display address back to a valid position on the LCD screen and send your character. Every character you define has an ascii value of 0 - 7. For example, to display your first character, send the number 0x00 as data. If you have a second, third or fourth (or so on) character defined, send data 0x01, 0x02, 0x03 (and so on). I have my code configured as follows:
This will display our custom character.
Here's a complete program that puts it all into context:
The above program utilizes my HD44780 C18 Driver Code.
Thursday, February 19, 2009
Wednesday, February 18, 2009
Tuesday, February 17, 2009
- 74HC595 - 8-Bit Shift Registers with Output Latches - Datasheet at Futurlec - $0.50 each.
- UCN5832 (a bigger version of the 595)
Sunday, February 15, 2009
The PIC18 series have a maximum internal oscillator frequency of 8 MHz, which translates to 2 MIPS. However, the PIC can run at much higher speeds (especially when using an external clock source). Using the PIC's PLL, one is able to multiply the clock source by up to 4 times. This is even software-controllable if using the internal clock source. Using the maximum speed of the internal oscillator, the PIC can run at up to 32 MHZ with PLL enabled. This yields blazing fast performance of 8 MIPS. Best of all, you can turn this feature on or off as you please to control power consumption. Using the PLL is very easy.
We must first ensure that we are using the internal oscillator. So, in C18, declare a configuration option like this:
#pragma config OSC = INTIO67
Next, we must either configure the internal oscillator to run at 4 or 8 MHz. The PLL will not be enabled on any other configuration. Since we're opting for speed here, let's set it at 8 MHz. Put the following as the first line in your main() function:
OSCCON = 0b01110000;
Note that the last two bits of OSCCON must be 00. And finally, to enable the PLL, add the next line right after:
OSCTUNE = 0b01011111;
This enables the PLL and runs the PIC at the maximum possible frequency using only the internal oscillator - 8 MIPS @ 32 MHz. To toggle the PLL on or off, simply set OSCTUNEbits.PLLEN to either 1 or 0, respectively. Refer to the datasheet for information on how to fine-tune the PLL.
Saturday, February 14, 2009
Friday, February 13, 2009
Thursday, February 12, 2009
Thursday, February 5, 2009
I've updated this example code to work with the latest Microchip XC8 compiler. The code is working perfectly with a PIC18F14K50, but can be very easily modified for use with any PIC.
Wednesday, February 4, 2009
To set the data direction, use the TRISX register like you normally would. For example, if I want to make my PORTC all output, I would use:
TRISC = 0x00; In hexadecimal notation
TRISC = 0b00000000; In binary notation.
Once the tristate registers have been set, you can begin to send data through the I/O pins. You can do this directly by writing to the PORTX register or control the individual bits with PORTXbits.RXn.
For example, to make pin 6 of PORTC a logic "1", you would do:
PORTCbits.RC6 = 1;
Reading the data from the ports follows the same pattern. Remember to set the TRISX variable to the right value in order to read data.
They are declared like this:
#pragma [option] = [value]
For example, my usual options are:
#pragma config OSC = INTIO67
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config PWRT = ON
#pragma config BOREN = OFF
#pragma config WDT = OFF
#pragma config MCLRE = OFF
#pragma config PBADEN = OFF
#pragma config LVP = OFF
Declare them just under your #includes.
Another essential thing to do when developing with your chip is to define a clock source and set the frequency of oscillation. In the above configuration settings, the OSC has been declared to use the internal clock source. This is advantageous because no external circuitry is required.
The OSCCON register controls the clock frequency of the inter clock source. The following code will set it to the maximum frequency of the PIC18F2620 - 8 MHz.
OSCCON = 0b01110010;
The above code should be the first line in your main() function - more on this later.
Tuesday, February 3, 2009
I believe that the PIC18 series is the best family when diving into the world of microcontrollers. Myself, I have a PIC18F2620. It's a solid, all round, feature-rich chip with lots of flash and ram (64K, 3K). It's really easy to work with, very reliable, comes in a 28 pin DIP package and is compatible with the Microchip C18 compiler.
This tutorial assumes that you know basic electronics and how to wire up a breadboard or solder your components prototyping board. It is also assumed that the reader knows basic C programming and is able to understand and modify basic C code to his/her requirements.
To get started, you'll need a PIC18 series microcontroller (such as the PIC18F2620). To program the chip, you'll need an ICSP programmer. I recommend the PICKIT2 as it is Microchip's own development programmer, is compatible with a wide range of chips, can do very easy UART communication between the PIC and PC and can even act as a mini logic analyzer. You'll also need a small development board (a breadboard or prototyping board, doesn't matter). And of course, you'll need a computer to use as a development machine. Your operating system doesn't matter, as long as you know your way around it well enough.
Setting Up The Circuit
To begin, wire up your circuit as follows:
Then connect the PICKIT2 and load the "PICKIT2 Operating System" onto the chip.
Writing Your First Program
Will be in the next post...