Posts

Showing posts from June, 2013

PIC24, DsPIC33F and DsPIC30F UART implementation Code + Proteus Simulation

Image
This post will help us to transmit data (bytes) using serial port (UART). A lot of debugging is done using serial ports. It is most convenient way of debugging for Engineers around the world.
I am using MPLAB x IDE and C30 Compiler and Proteus Simulation on v8.0 (can be downloaded from downloads section at the bottom of this post). This code will work on PIC24, DsPIC33 and DsPIC30 (16bit microcontroller) by changing only the microcontroller and header file.
Proteus Simulation:
            In this figure, I used virtual terminal that will show what data is transmitted by UART1.


Code:
In the following figure II. First I configure Uart1 module in OpenUART1() which is set according to basic functions explained in comments. I used high speed BRG which has formula. I a while loop I print a string with linefeed and carriage return at the end so it looks good.
In the following figure, we have BusyUART1() which continuously monitors the flag which means that UART is bust in transmitting previous  da…

Digital Clock using PIC and LCD 16x2 with time Set function (Code and Proteus Simulation)

Image
This post will help us to understand how to implement Digital Clock with time set control functions using microcontroller and LCD 16x2.
I am using MPLAB x IDE and C30 Compiler and Proteus Simulation on v8.0 (can be downloaded from downloads section at the bottom of this post). This code will work on PIC24, DsPIC33 and DsPIC30 (16bit microcontroller) by slightly changing code.
I supposed that you know following. How to blink an LED (if not then I suggest you to read this (link) first before continuing this post)Digital Clock using 7 segments. (If not then I suggest you to read this (link) first before continuing this post).How to use timer 1 interrupt. (If not then I suggest you to read this (link) first before continuing this post).How to interface LCD (If not then I suggest you to read this (link) first before continuing this post).
Proteus Simulation:

            In this figure, as I used three push buttons one is to set, up and down. With PortA.


Code:
In the following figure. I first ini…

Digital Clock using 7 segment Display with PIC microcontroller (Code and Proteus Simulation)

Image
This post will help us to understand how to multiplex 7 segment display with PIC microcontroller. One major importance of multiplexing 7 segment display is to get rid of external components such as latches or other ICs.
The trick behind multiplexing is that you enable one seven segment at a time. All of 7 segments are connected to a common parallel bus with a common node (ie Common Anode and Cathode) connected to transistor as shown in figure. So this means microcontroller will switch on specific transistor and put the segment data onto the port and only that 7 segment will light up. And this process go on for other 7 segments with a high speed fast enough that our eyes can’t see it. We only see all segments light up at all the time.
I am using MPLAB x IDE and C30 Compiler and Proteus Simulation on v8.0 (can be downloaded from downloads section at the bottom of this post). This code will work on PIC24, DsPIC33 and DsPIC30 (16bit microcontroller) by slightly changing code.
I supposed tha…

How to get interrupt on change of logic on Pins (Input Change Notification). Code + Proteus Simulation

Image
This post will help us to understand how to get interrupt on change of logic at selected pins. The importance of this is you get interrupt whenever state of the pin changes. Even when your microcontroller is in sleep mode when the clocks are disabled.
I am using MPLAB x IDE and C30 Compiler and Proteus Simulation on v8.0 (can be downloaded from downloads section at the bottom of this post). This code will work on PIC24, DsPIC33F and DsPIC30F (16bit microcontroller) by slightly changing code.
I supposed that you know following.
How to blink an LED (if not then I suggest you to read this (link) first before continuing this post)How to get input from button. (if not then I suggest you to read this (link) first before continuing this post) We have 11 external signals in 14pin PIC24. These pins are labeled as CNx where x is number of input change notifications all of these pins can be configured by setting their register values mentioned below in this post.
            Each pin has its own pul…

How to get Input from Button in PIC24 Code and Proteus Simulation

Image
This post will help us to understand how to get input from external source. I am using MPLAB x IDE and C30 Compiler and Proteus Simulation on v8.0 (can be downloaded from downloads section at the bottom of this post). This code will work on PIC24, DsPIC33 and DsPIC30 (16bit microcontroller) by slightly changing code.
I supposed that you know following.
·How to blink an LED (if not then I suggest you to read this (link) first before continuing this post)

Proteus Simulation:
            In this figure, a button is attached to PortA pin 7. Every time when button is pressed blue LED will glow and yellow LED will be off and vice versa.
Code:
In the following figure I made button pin as input and LEDs pins as output and as shown in circuit I am not using any pullup or pulldown resistor that’s why I enabled PIC internal Pullup resistor by writing 1 to “CNPU1bits.CN9PUE = 1”. Remember this is weak Pullup. By using this resistor I reduce one external component from hardware. You may use External re…