; *******************************************************************
; PICkit 2 Lesson 1 - "Hello World"
;
; This turns on DS1 LED on the Low Pin Count Demo Board.
;
; *******************************************************************
; * See Low Pin Count Demo Board User's Guide for Lesson Information*
; *******************************************************************
; * NOTE: The PIC16F690 requires the AC162061 header for debugging *
; *******************************************************************
#include <p16F628a.inc>
__CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_OFF & _INTOSC_OSC_NOCLKOUT
org 0
Start:
bsf STATUS,RP0 ; select Register Page 1
bcf TRISB,0 ; make IO Pin B0 an output
bcf STATUS,RP0 ; back to Register Page 0
bsf PORTB,0 ; turn on LED B0 (DS1)
goto $ ; wait here
end
; *******************************************************************
; PICkit 2 Lesson 2 - "Blink"
;
; First lesson showed how to make an LED turn on,
; Now we'll look at how to make it blink. Delay loops are necessary
; to slow down the on and off commands so they are visible to humans.
; *******************************************************************
; * See Low Pin Count Demo Board User's Guide for Lesson Information*
; *******************************************************************
; * NOTE: The PIC16F628a requires the AC162061 header for debugging *
; *******************************************************************
; *******************************************************************
#include <p16F628a.inc>
__CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_OFF & _INTOSC_OSC_NOCLKOUT
cblock 0x20
Delay1 ; Define two file registers for the
Delay2 ; delay loop
endc
org 0
Start:
bsf STATUS,RP0 ; select Register Page 1
bcf TRISB,0 ; make IO Pin B.0 an output
bcf STATUS,RP0 ; back to Register Page 0
MainLoop:
bsf PORTB,0 ; turn on LED B0
OndelayLoop:
decfsz Delay1,f ; Waste time.
goto OndelayLoop ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
decfsz Delay2,f ; The outer loop takes and additional 3 instructions per lap * 256 loops
goto OndelayLoop ; (768+3) * 256 = 197376 instructions / 1M instructions per second = 0.197 sec.
; call it a two-tenths of a second.
bcf PORTB,0 ; Turn off LED B0
OffDelayLoop:
decfsz Delay1,f ; same delay as above
goto OffDelayLoop
decfsz Delay2,f
goto OffDelayLoop
goto MainLoop ; Do it again...
end
; *******************************************************************
; PICkit 2 Lesson 2 - "Rotate"
;
; First lesson showed how to make an LED turn on,
; Now we'll look at how to make it Rotate. Delay loops are necessary
; to slow down the on and off commands so they are visible to humans.
; *******************************************************************
; * See Low Pin Count Demo Board User's Guide for Lesson Information*
; *******************************************************************
; * NOTE: The PIC16F628a requires the AC162061 header for debugging *
; *******************************************************************
; *******************************************************************
#include <p16F628a.inc>
__CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_OFF & _INTOSC_OSC_NOCLKOUT
cblock 0x20
Delay1 ; Assign an address to label Delay1
Delay2
Display ; define a variable to hold the diplay
endc
org 0
Start:
bsf STATUS,RP0 ; select Register Page 1
clrf TRISB ; make IO PortC all output
bcf STATUS,RP0 ; back to Register Page 0
movlw 0x08
movwf Display
MainLoop:
movf Display,w ; Copy the display to the LEDs
movwf PORTB
OndelayLoop:
decfsz Delay1,f ; Waste time.
goto OndelayLoop ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
decfsz Delay2,f ; The outer loop takes and additional 3 instructions per lap * 256 loops
goto OndelayLoop ; (768+3) * 256 = 197376 instructions / 1M instructions per second = 0.197 sec.
; call it a two-tenths of a second.
bcf STATUS,C ; ensure the carry bit is clear
rrf Display,f
btfsc STATUS,C ; Did the bit rotate into the carry?
bsf Display,3 ; yes, put it into bit 3.
goto MainLoop
end
;TRISA Bit Map
;|RA7|RA6|RA5|RA4|RA3|RA2|RA1|RA0|
;| 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
banksel TRISA ;select bank in which SFR TRISA resides
movlw b'01010101' ;set RA7, RA5, RA3 and RA1 as output
movwf TRISA ;set RA6, RA4, RA2 and RA0 as input
;TRISB Bit Map
;|RB7|RB6|RB5|RB4|RB3|RB2|RB1|RB0|
;| 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
movlw b'10101010' ;set RB7, RB5, RB3 and RB1 as input
movwf TRISB ;set RB6, RB4, RB2 and RB0 as output
;TRISA Bit Map
;|RA7|RA6|RA5|RA4|RA3|RA2|RA1|RA0|
;| 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
banksel TRISA ;select bank in which SFR TRISA resides
movlw b'01010101' ;set RA7, RA5, RA3 and RA1 as output
movwf TRISA ;set RA6, RA4, RA2 and RA0 as input
;TRISB Bit Map
;|RB7|RB6|RB5|RB4|RB3|RB2|RB1|RB0|
;| 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
movlw b'10101010' ;set RB7, RB5, RB3 and RB1 as input
movwf TRISB ;set RB6, RB4, RB2 and RB0 as output
;PORTA Bit Map
;|RA7|RA6|RA5|RA4|RA3|RA2|RA1|RA0|
;| 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
banksel PORTA ;select bank in which SFR PORTA resides
movlw b'10101010' ;set all PORT A outputs "high"
movwf PORTA
;PORTB Bit Map
;|RB7|RB6|RB5|RB4|RB3|RB2|RB1|RB0|
;| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
movlw b'00000000' ;set all PORT B outputs "low"
movwf PORTB
I got started about 6 months ago with the Pickit2 and the LPC from microchip. I did all of the lessons in asm and then I got the oshonsoft simulator.
You can do a great deal of beginner stuff without having to build anything much physically.
I 'built' my first breadboard project after having done simulations on a 16f886 driving 20LEds & a 4 Digit 7 seg display and with a full menu interface driven by a 2 button interface.
The code was several thousand asm commands long. The device is a multifunction device involving 5 adc inputs, 4 MOSFET driven pwr outputs, 2 of them PWM plus a PID controller, eprom data logging, ..etc. etc. I learned to do ALL that between a simulator AND this remarkable forum.
After building the 1st physical device, it took about a week to get it working becuz I had to read the data sheet carefully for things like the ICSP setup and avoiding low voltage programming and fixing the usual wiring issues.
Now if u have no prior electronics experience, then building the simpler boards is a must, I skipped that since I am comfortable with prototyping. There is no exchange for learning by doing.
Also, always make a real effort to debug b4 you post, and post your commented code . Use the forum search feature. Also check out
Make little functions that u debug one at a time. Then link them together to make larger functions. That way u keep things manageable.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?