![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
As i am starting to practice on more chips i use the blink as a start... But i ran into a issue... it doesnt want to blink
Code:
list p=16f627A ; list directive to define processor #include <P16F627A.inc> ; processor specific variable definitions __CONFIG 0x3f78 ;_CP_OFF & _DATA_CP_OFF & _LVP_OFF & _WDT_OFF & _INTOSC_OSC_CLKOUT cblock 0x00 d1 d2 d3 endc ORG 0x00 ; processor reset vector Main clrf PORTA ;Initialize PORTA by setting output data latches movlw 0x07 ;Turn comparators off and movwf CMCON ;enable pins for I/O functions bsf STATUS, RP0 ;select bank 1 movlw 0x1D ;data direction movwf TRISA ;set PortA all outputs bsf PCON, 3 ;OSCF: INTOSC oscillator frequency bit: 1=4 MHz typical bcf STATUS, RP0 ;select bank 0 Loop bsf PORTA, 1 ;set RA1 High call Delay bcf PORTA, 1 ;set RA1 Low goto Loop ;go back and do it again Delay movlw 0x03 movwf d1 movlw 0x18 movwf d2 movlw 0x02 movwf d3 Delay_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto Delay_0 goto $+1 return END ; directive 'end of program' |
|
|
|
|
|
|
(permalink) |
|
Well it is obvious, after bsf PORTA,1 you call delay but after bcf PORTA,1 you forgot to call it again and jump to Loop which sets the output to 1 again.
Petr |
|
|
|
|
|
|
(permalink) | |
|
Quote:
|
||
|
|
|
|
|
(permalink) |
|
[quote=AtomSoft]As i am starting to practice on more chips i use the blink as a start... But i ran into a issue... it doesnt want to blink
The ICD2 can't debug the 16F628A either, it doesn't have debug support built in. The 16F88 does though. Of course you could simply simulate it in MPLAB. |
|
|
|
|
|
|
(permalink) |
|
RAM starts at 0x20 on the 16F627A PIC
Code:
list p=16f627A ; list directive to define processor
#include <P16F627A.inc> ; processor specific variable definitions
__CONFIG _WDT_OFF & _INTOSC_OSC_NOCLKOUT
cblock 0x20
d1,d2,d3
endc
ORG 0x00 ; processor reset vector
Main
clrf PORTA ;Initialize PORTA by setting output data latches
movlw 0x07 ;Turn comparators off and
movwf CMCON ;enable pins for I/O functions
bsf STATUS, RP0 ;select bank 1
movlw 0x1D ;data direction
movwf TRISA ;set PortA all outputs
bsf PCON, 3 ;OSCF: INTOSC oscillator frequency bit: 1=4 MHz typical
bcf STATUS, RP0 ;select bank 0
Loop
bsf PORTA, 1 ;set RA1 High
call Delay
bcf PORTA, 1 ;set RA1 Low
goto Loop ;go back and do it again
Delay
movlw 0x03
movwf d1
movlw 0x18
movwf d2
movlw 0x02
movwf d3
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay_0
goto $+1
return
END ; directive 'end of program' END
Last edited by blueroomelectronics; 11th April 2008 at 04:19 PM. |
|
|
|
|
|
|
(permalink) |
|
Not 100% true, ICD2 *can* debug it but not alone, it is necessary to buy a special adapter from Microchip (AC162053) - costs about $35 - that allows you to debug code for 627A/628A/648A.
Of course 16F88 can be debugged with ICD2 or PicKit2 alone, without any additional hardware. Petr |
|
|
|
|
|
|
(permalink) |
|
ok thanks guys i cant believe i missed something so small and yeah i know it starts at 0x20 but just habit of 00 lol thanks.
|
|
|
|
|
|
|
(permalink) |
|
ICD? Learn to use the simulator in the IDE very very good period. A few taps of the single step F7 key would have solved this in under 30 seconds. I never actually used ICD, do not know how, don't want to know.
Standardize your delays. Make a set for micro seconds, milli seconds, and seconds similar to my code below. Code:
Set LED Call usec100 Call usec100 Clear LED Call usec100 Call usec100 Loop movlw .50 movw milli_time ; Load milli_time only once because it is persisted into milli_time_temp. Set LED ; A.K.A non-volatile. Call milli_delay Clear LED Call milli_delay Loop Code:
USEC_10:
GOTO $ + 1
GOTO $ + 1
GOTO $ + 1
RETURN
USEC_20:
GOTO $ + 1
GOTO $ + 1
GOTO $ + 1
GOTO $ + 1
GOTO $ + 1
GOTO $ + 1
GOTO $ + 1
GOTO $ + 1
GOTO $ + 1
RETURN
USEC_100: ;----FORMULA--4MHZ CLOCK---------
MOVLW .31 ; [3(CNTJ-1)+2] + CHANGE
MOVWF CNTJ ; CHANGE = 8 USEC
DECFSZ CNTJ, F ; [3(CNTJ-1)+2] + 8
GOTO $ - 1 ;--------------------------------
NOP
NOP
RETURN
MS_DELAY:
MOVF MILLI_TIME, W ;---------------------------------------
MOVW MILLI_TIME_TEMP ;MILLI SECOND DELAY
MS_LOOP MOVLW 0XA4 ;DELAY = X MILLI-SECOND (4MHZ CLOCK).
MOVWF CNTJ ;---------------------------------------
DECFSZ CNTJ, F
GOTO $ - 1
MOVLW 0XA4
MOVWF CNTJ
DECFSZ CNTJ, F
GOTO $ - 1
DECFSZ MS_TIME_TEMP, F ;IF COUNTER ENDS,
GOTO MS_LOOP ;ELSE- REPEAT
RETURN ;THEN- EXIT LOOP
Last edited by donniedj; 11th April 2008 at 08:36 PM. |
|
|
|
|
|
|
(permalink) |
|
Simulator just doesnt work in some cases.
Like here is my end code for a 7 Seg Display count up 0 - 9... I wouldnt want to try to simulate this.. would get confusing... RA5 and RA7 are inuse so used RB0 and RB1... Code:
list p=16f627A ; list directive to define processor #include <P16F627A.inc> ; processor specific variable definitions __CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _WDT_OFF & _INTOSC_OSC_NOCLKOUT cblock 0x20 d1 d2 d3 endc ORG 0x00 ; processor reset vector Main clrf PORTA ;Initialize PORTA by setting output data latches movlw 0x07 ;Turn comparators off and movwf CMCON ;enable pins for I/O functions bsf STATUS, RP0 ;select bank 1 movlw 0x00 ;data direction movwf TRISA ;set PortA all outputs movwf TRISB ;set PortB all outputs bsf PCON, 3 ;OSCF: INTOSC oscillator frequency bit: 1=4 MHz typical bcf STATUS, RP0 ;select bank 0 Loop movlw b'01011111' ;Show 0 movwf PORTA movlw 0x01 ; RB0 = E RB1 = G movwf PORTB call Delay ;//////////////////////////////////////////////////// movlw b'00000110' ;Show 1 movwf PORTA movlw 0x00 ; RB0 = E RB1 = G movwf PORTB call Delay ;//////////////////////////////////////////////////// movlw b'10011011' ;Show 2 movwf PORTA movlw 0x03 ; RB0 = E RB1 = G movwf PORTB call Delay ;//////////////////////////////////////////////////// movlw b'10001111' ;Show 3 movwf PORTA movlw 0x02 ; RB0 = E RB1 = G movwf PORTB call Delay ;//////////////////////////////////////////////////// movlw b'11000110' ;Show 4 movwf PORTA movlw 0x02 ; RB0 = E RB1 = G movwf PORTB call Delay ;//////////////////////////////////////////////////// movlw b'11001101' ;Show 5 movwf PORTA movlw 0x02 ; RB0 = E RB1 = G movwf PORTB call Delay ;//////////////////////////////////////////////////// movlw b'11011101' ;Show 6 movwf PORTA movlw 0x03 ; RB0 = E RB1 = G movwf PORTB call Delay ;//////////////////////////////////////////////////// movlw b'00000111' ;Show 7 movwf PORTA movlw 0x00 ; RB0 = E RB1 = G movwf PORTB call Delay ;//////////////////////////////////////////////////// movlw b'11011111' ;Show 8 movwf PORTA movlw 0x03 ; RB0 = E RB1 = G movwf PORTB call Delay ;//////////////////////////////////////////////////// movlw b'11011111' ;Show 9 movwf PORTA movlw 0x02 ; RB0 = E RB1 = G movwf PORTB call Delay ;//////////////////////////////////////////////////// goto Loop Delay ; 1 Sec Delay movlw 0x07 movwf d1 movlw 0x2F movwf d2 movlw 0x03 movwf d3 Delay_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto Delay_0 goto $+1 goto $+1 goto $+1 return END ; directive 'end of program' |
|
|
|
|
|
|
(permalink) |
|
Of course the use of the simulator is limited but sometimes it is still useful - for example I used it yesterday to quickly verify my delay loop produces the exact delay and not a few instr. cycles longer or shorter... using the logic analyzer inside the simulator it was easy and quick.
Petr |
|
|
|
|
|
|
(permalink) |
|
How come sometimes my Logic Analyzer isnt available? Like i cant open it because its greyed out?
|
|
|
|
|
|
|
(permalink) |
|
Not sure, which PIC?
|
|
|
|
|
|
|
(permalink) |
|
sometimes the 1320 but remember its on simulator and its greyed out in MPLAB of course
|
|
|
|
|
|
|
(permalink) |
|
In a pinch the OshonSoft simulator has a 7 segment display. It's demo is limited to 30 uses.
|
|
|
|
|
|
|
(permalink) |
|
Setting d1,d2,d3 in a watch and pressing the F7 would have revealed that d1 to d3 were not being assigned and overwritten, and that a delay between BCF and GOTO were missing.
Code:
cblock 0x00
d1,d2,d3
endc
ORG 0x00 ; processor reset vector
Loop
bsf PORTA, 1 ;set RA1 High
call Delay
bcf PORTA, 1 ;set RA1 Low
goto Loop ;go back and do it again
|
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| Switching power supply issue. | dbtoutfit | General Electronics Chat | 41 | 25th March 2008 03:21 AM |
| issue with my handheld console draining batterys... | tgg | General Electronics Chat | 0 | 26th September 2007 03:37 AM |
| ESD Issue? Kind of long | Peach | General Electronics Chat | 21 | 8th April 2007 01:47 AM |
| Need Someone Realy Good At Computers..... REAL good | PapaSmurf | Chit-Chat | 16 | 3rd May 2006 10:30 PM |
| EPE magazine - may 2001 issue - PIC graphics LCD scope | evandude | General Electronics Chat | 4 | 12th December 2004 05:43 PM |