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

No comments:

Post a Comment