So you do already have a programmer and a pic microcontroller, but you don't have a project to work on. Here we start with a simple thing for beginners : LEDs. It's a very simple method to output a signal from a pic , and it would be great for your first project.
So what you will need:
-a pic microcontroller (i used PIC16F628 here)
-a 12k resistor
-2 resistors of 1k
-2 LEDs
-a bush button .
-some wires.
The circuit diagram:
Now the program(led_test.asm):
;************************************************************
; Processor: PIC16F628 at 4 MHz using internal RC oscillator
; Function: Flash a 2LEDs connected to RA2 and RA3
; Author: PIC DIY's
; Website: http://www.pic-diys.blogspot.com
;************************************************************
LIST P=16F628, R=DEC ; Use the PIC16F628 and decimal system
#include "P16F628.INC" ; Include header file
__config _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON
CBLOCK 0x20 ; Declare variable addresses starting at 0x20
Loop1,Loop2
ENDC
;
; -----------
; INITIALIZE
; -----------
;
ORG 0x000 ; Program starts at 0x000
CLRF PORTA ; Initialize port A
CLRF PORTB ; Initialize port B
BSF STATUS,RP0 ; RAM bank 1
CLRF TRISA ; All pins port A output
CLRF TRISB ; All pins port B output
BCF STATUS,RP0 ; RAM bank 0
;
; ------------------------
; FUNCTION OF PORT A PINS
; ------------------------
;
MOVLW 7
MOVWF CMCON ; Comparators off, all pins digital I/O
;
; ----------
; MAIN LOOP
; ----------
;
Main BSF PORTA,2 ; Turn on LED connected to RA2
CALL dilay
BCF PORTA,2 ; Turn off LED connected to RA2
CALL dilay
BSF PORTA,2 ;Turn on LED connected to RA2
CALL dilay
BCF PORTA,2 ;Turn off LED connected to RA2
CALL delay
BSF PORTA,3 ;Turn on LED connected to RA3
CALL delay
BCF PORTA,3 ;Turn off LED connected to RA3
CALL dilay
GOTO Main
;
; ---------------
; DELAY 120 MSEC
; ---------------
;
delay MOVLW 120
MOVWF Loop1
;
; ---------------
; DiLAY 80 MSEC
; ---------------
;
dilay MOVLW 80
MOVWF Loop1
Outer MOVLW 200
MOVWF Loop2
Inner NOP
NOP
DECFSZ Loop2,F
GOTO Inner ; Inner loop = 5 usec.
DECFSZ Loop1,F
GOTO Outer
RETURN
END
You can use the MPASM from Microchip to assemble the programme . It's easy and nice to work with.
After assembling the programme , burn it on your pic (PIC 16F628 used in this project). You can have a look on our simple pic programmer tutorail here.
Remarque: You can always use an usb cable to have a quick 5V. the red wire is the positive(5v) and the black one is the ground (-).
I guess that this is all what i got , any question you can comment on. You can follow my posts with e-mail.
Thank's for your attention guys!
Monta Ghanmy
So what you will need:
-a pic microcontroller (i used PIC16F628 here)
-a 12k resistor
-2 resistors of 1k
-2 LEDs
-a bush button .
-some wires.
The circuit diagram:
;************************************************************
; Processor: PIC16F628 at 4 MHz using internal RC oscillator
; Function: Flash a 2LEDs connected to RA2 and RA3
; Author: PIC DIY's
; Website: http://www.pic-diys.blogspot.com
;************************************************************
LIST P=16F628, R=DEC ; Use the PIC16F628 and decimal system
#include "P16F628.INC" ; Include header file
__config _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON
CBLOCK 0x20 ; Declare variable addresses starting at 0x20
Loop1,Loop2
ENDC
;
; -----------
; INITIALIZE
; -----------
;
ORG 0x000 ; Program starts at 0x000
CLRF PORTA ; Initialize port A
CLRF PORTB ; Initialize port B
BSF STATUS,RP0 ; RAM bank 1
CLRF TRISA ; All pins port A output
CLRF TRISB ; All pins port B output
BCF STATUS,RP0 ; RAM bank 0
;
; ------------------------
; FUNCTION OF PORT A PINS
; ------------------------
;
MOVLW 7
MOVWF CMCON ; Comparators off, all pins digital I/O
;
; ----------
; MAIN LOOP
; ----------
;
Main BSF PORTA,2 ; Turn on LED connected to RA2
CALL dilay
BCF PORTA,2 ; Turn off LED connected to RA2
CALL dilay
BSF PORTA,2 ;Turn on LED connected to RA2
CALL dilay
BCF PORTA,2 ;Turn off LED connected to RA2
CALL delay
BSF PORTA,3 ;Turn on LED connected to RA3
CALL delay
BCF PORTA,3 ;Turn off LED connected to RA3
CALL dilay
GOTO Main
;
; ---------------
; DELAY 120 MSEC
; ---------------
;
delay MOVLW 120
MOVWF Loop1
;
; ---------------
; DiLAY 80 MSEC
; ---------------
;
dilay MOVLW 80
MOVWF Loop1
Outer MOVLW 200
MOVWF Loop2
Inner NOP
NOP
DECFSZ Loop2,F
GOTO Inner ; Inner loop = 5 usec.
DECFSZ Loop1,F
GOTO Outer
RETURN
END
You can use the MPASM from Microchip to assemble the programme . It's easy and nice to work with.
After assembling the programme , burn it on your pic (PIC 16F628 used in this project). You can have a look on our simple pic programmer tutorail here.
Remarque: You can always use an usb cable to have a quick 5V. the red wire is the positive(5v) and the black one is the ground (-).
I guess that this is all what i got , any question you can comment on. You can follow my posts with e-mail.
Thank's for your attention guys!
No comments:
Post a Comment