Friday, May 17, 2013

16*2 LCD module driver program

Here is the program to drive a 16*2 LCD module. First install PIC C compiler downloaded from internet or one that you have purchased. Install the compiler and create a new project in New project wizard,then initial setting ie. device selection, oscillator frequency, are done in the first page.
 In the next opening page we have to write the program in C.

PIC C compiler have bult-in functions and can be directly be used. Compile the program and if any errors correct it, then recompile. For simulation of the hex code we can use PIC simulator IDE.





CODE:

#include <16F877A.h>
#device adc=8
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES WRT_50%                  //Lower half of Program Memory is Write Protected
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
///////////////////////////////////////////////////LCD///////////////////////////////////////////////////////

void command()                               //     command control function
{
output_low(pin_c0);     //Rgister Select (RS)= 0  
output_high(pin_c2);
delay_ms(10);
output_low(pin_c2);      //E = 0
}

void data()                                     //    Data flow control function
{
output_high(pin_c0);    //RS = 1
output_high(pin_c2);
delay_ms(10);
output_low(pin_c2);      //E = 0
}
void lcd_init()                                //     LCD initialization
  
 {
   output_b(0x38);
   command();
   output_b(0x0E);
   command();
   output_b(0x01);
   command();
   output_b(0x80);
   command();
 }
 char c;      
 void main()
    {
   char d[] = "YES ITS WORKING...";
   int i=0;
   lcd_init();
   while(d[i]!='\0')                //                         
      {
      output_b(d[i]);              //  sending charactrs (byte) to the PORTB
      data();
      delay_ms(10);
      i++;
      }
   while(1)
   {
   output_b(0x18);              // Scrolling the display after entire data entered to the display
   command();
   }
}

Wednesday, May 8, 2013

PIC MICROCONTROLLER

                                              
                                                      PIC MICROCONTROLLER

      PIC is a family of microcontrollers having Harvard architecture microcontrollers made by Microchip Technology, derived from the PIC1650. originally developed by General Instrument's Microelectronics Division. The name PIC refers to Peripheral Interface Controller PICs are popular with both industrial developers and hobbyists alike due to their low cost, wide availability, large user base, extensive collection of application notes, availability of low cost or free development tools, and serial programming (and re-programming with flash memory) capability.


1. LED FLASH code basic tutorial

Below given asm code is written and compiled using MPLAB IDE. You can download MPLAB IDE directly from Microchip website and install the software in your PC. Also download a crack version of PIC simulator IDE to simulate the hex code generated after compilation. 
code:

;Example: Asm code for simple LED flash to study the Basic coding for ports

INCLUDE "P16F877A.INC"                 
CBLOCK 0x20
R0                                              ;Defined registers
R1
ENDC

ORG 0X00                             ;starting from memory location Address0X00
BSF STATUS,RP0                ;selecting register bank 0
MOVLW 0x00                      ;(processor starts execution from this address)        
MOVWF TRISB                   ;setting PORTB as output
BCF STATUS,RP0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LOOP2:
                                                 ; PORTB is selected to LED flash.
MOVLW 0XFF
MOVWF PORTB                    ;Moving value 0X00 to PORTB
CALL DELAY                         ;Calling DELAY subroutine
CLRF PORTB
CALL DELAY
GOTO LOOP2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DELAY:                                            ;Time delay subroutine
MOVLW 0XFF
MOVWF R0
DECFSZ R0,1
RETURN
END
..................................................................................................................................................................
MPLAB
Open MPLAB IDE then select project tab and project wizard, select device we are going to use. Then browse for the folder in which we have to save new project, save project name and the new project will open.
open a new blank work space and save in the above project folder. We can see filename.mcw window in which right click on source files will provide an option to add new work file to the source files directory. then open again the work space to write the assembly code. After the success building load the hex code to the PIC simulator IDE.

Fig1. Writting assembly code to MPLAB IDE work space

The  generated hex code is Loaded to the PIC simulator IDE and starting simulation will result the visual LED flash.
Loading hex code to PIC simulator IDE is showen in the screen shot below. We can select the microcontroller that we are going to burn hex code in it. Open modules nedded from options and select file tab to load the hex file to the machine.


Fig1. PIC Simulator IDE