peterdeco1,
What programmer software and hardware are you using that causes the problem? We would all like to know. We want to avoid running in to the same difficulties.
peterdeco1,
What programmer software and hardware are you using that causes the problem? We would all like to know. We want to avoid running in to the same difficulties.
Last edited by Dick Ivers; - 21st January 2006 at 20:28.
hi guys can any one help with assembly code for dimming an led using the pic16f88. ihave read the datasheet but i dont seem to underatand it i have come with code but it doesnt work can anybody tell me whats wrong with my code.
list p=16f88
INCLUDE "p16f88.inc"
_;****Set up the Constants****
STATUS equ 03h
TRISA equ 85h ;Address of the STATUS register
TRISB equ 86h
PORTA equ 05h ;Address of the tristate register for port A
PORTB equ 06h ;Address of Port A
COUNT1 equ 20h ;First counter for our delay loops
COUNT2 equ 21h ;Second counter for our delay loops
ANSEL equ 9Bh
OSCCON equ 8Fh
CCP1CON equ 17h
T2CON equ 12h
TMR2 equ 11h
CCPR1L equ 15h
PR2 equ 92h
PIR1 equ 0Ch
PIE1 equ 8Ch
movlw B'00000000' ; 31.25khz
bsf STATUS, 5
movwf OSCCON
nop
nop
nop
bcf STATUS, 5
movlw b'00111100'
movwf CCP1CON
bsf 03h,5 ;Go to Bank 1
movlw 00h ;Put 00000 into W
movwf TRISA ;Move 00000 onto TRISA – all pins set to output
movlw 00h ;Set the Port B pins
movwf TRISB ;to output. ;Put 00000 into W
movlw 00h
movwf ANSEL ;Move 00000 onto TRISA – all pins set to output
movlw b'11111111'
movwf PR2
bcf 03h,5 ;Come back to Bank 0
movlw b'00001111'
movwf TMR2
Start
movlw b'00001111'
movwf CCPR1L ; set duty cycle
Loop1
decfsz CCPR1L ;dimming led by varying the duty cycle
goto Loop1
goto Start
end
I'll bet at least on the configuration fuses settings... AND... is there any specific reason why you want to run your PIC @ 32KHz?
i didn't did the calc, but i feel your current setting doesn't work anyways...
try the following
Sorry, ASM is really not my cup of teaCode:list p=16f88 INCLUDE "p16f88.inc" ; Program Configuration Register 1 __CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_IO ; Program Configuration Register 2 __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF errorlevel -302 ; disable ' ensure .. bank pouet pouet' warning message BANKSEL OSCCON MOVLW B'01100000' MOVWF OSCCON ; 4 MHz INT CLOCK MODE BTFSS OSCCON,IOFS ; wait 'till int osc is stable GOTO $-1 BANKSEL PORTB CLRF PORTB ; Clear all CLRF PORTA ; outputs BANKSEL TRISA CLRF TRISA ; all pins set to output CLRF TRISB ; BANKSEL ANSEL CLRF ANSEL ; Disable all ADCs ; ; PWM Setup ; --------- BANKSEL PR2 movlw .249 ; ~250Hz PWM FREQUENCY movwf PR2 BANKSEL T2CON movlw b'00000111' ; prescaler 1:16, Timer2=on movwf T2CON BANKSEL CCP1CON movlw b'00001100' ; pwm mode movwf CCP1CON Start BANKSEL CCPR1L movlw .250 movwf CCPR1L ; set duty cycle to ~max, 100% Loop1 ; ((10+bananas) *250) uSec delay loop ; to provide slower fading effect goto $+1 goto $+1 goto $+1 goto $+1 goto $+1 DECFSZ W,F GOTO Loop1 decfsz CCPR1L,F ; dimming led by varying the duty cycle goto Loop1 goto Start endSo i'll not be surprised if some comes with a better solution, or with some constructive comments on the above (apart that i should care a little bit more about the bank switching... i feel there's a few useless BANKSEL here and there... that's what happen when you're lazy
)
<hr>
Please, next time, try to not double, triple post the same question on various forum section.
Last edited by mister_e; - 13th November 2007 at 00:52.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
hey thanks alot ,it works. i have just tested it.can you please tell me what $+1 means so that i can change the code to control a motor.if you can send me sample assembly code on how to use the analogue to digital converter on the pic16f88. code that can display a binary values on leds of a varying voltage signal. your help would be highly appreciated
$+1 mean 'from here to the next instruction' this avoid to use labels. The GOTO $+1 just jump to the next instruction. a single goto use 2 instruction cycle.
$-1 jump to the previous instruction.
You can also change the 1 to whatever else amount of line... but this could make your code harder to read.
<hr>
i'll look at that later today for the other code.
Hey! you're such a lucky guy to have ASM support on a PICBASIC forum.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
play with this one
Code:; --------------------------------------------------------------- ; ; Simple program which display ADC results of AN0 ; to 8 LED connected to PORTB<7:0> ; ; Enjoy! ; Steve AKA Mister_e ; ; --------------------------------------------------------------- list p=16f88, W=-302 ; bank switching INCLUDE "p16f88.inc" ; Program Configuration Register 1 CFG1 = _INTRC_IO & _MCLR_OFF & _BODEN_ON & _PWRTE_ON & _WDT_OFF & _LVP_OFF CFG2 = _DEBUG_OFF & _CP_OFF & _CCP1_RB0 & _WRT_PROTECT_OFF & _CPD_OFF __CONFIG _CONFIG1, CFG1 & CFG2 ; Program Configuration Register 2 __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF ORG 0 BANKSEL OSCCON MOVLW B'01100000' MOVWF OSCCON ; 4 MHz INT CLOCK MODE BTFSS OSCCON,IOFS ; wait 'till int osc is stable GOTO $-1 BANKSEL TRISA MOVLW .1 MOVWF TRISA ; porta.0 as input, other to output CLRF TRISB ; all pins set to output MOVLW .7 MOVWF CMCON ; disable analog comparator ; ; ADC setup ; --------- BANKSEL ANSEL MOVLW .1 MOVWF ANSEL ; Disable all ADCs but AN0 CLRF ADCON1 ; Left justified results ; ADCS2 : disabled ; Vref : Vdd, Vss BANKSEL ADCON0 MOVLW B'01000001' MOVWF ADCON0 ; ADCS : Fosc/8 ; select AN0 ; ADON = 1 ; ; Hardware initialisation ; ----------------------- CLRF PORTB ; Clear all CLRF PORTA ; outputs ; ; Program Start ; ------------- Start ; ; ADC Conversion ; -------------- MOVLW .12 ; ~12 uSec acquisition loop DECFSZ W,F ; GOTO $-1 ; BSF ADCON0, GO_DONE ; Start conversion BTFSC ADCON0, GO_DONE ; conversion finished? GOTO $-1 ; NO, wait again ; ; Display result ; -------------- MOVF ADRESH,W ; Move ADC result to Wreg MOVWF PORTB ; display it on PORTB GOTO Start END
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
hi ya am surely one lucky guy.i know i might me asking for alot but can u please send the schematic for the adc code. by the way am called gonza, am from uganda in eastafrica.its like am one of the very few people in my part of the world dealing with microcontrollers.its really cool stuff i must say...... thanks alot for the support i appreciate it.
Bookmarks