![]() |
![]() |
![]() |
|
|
|||||||
| 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) |
|
Okay, just to get myself back into having fun with PIC's, I wrote a little program to just make PORTA's bits turn on and off with a delay.
Code:
#include P16F876A.INC main BSF STATUS,5 MOVLW 0x00 MOVWF TRISA BCF STATUS,5 loop CALL delay COMF PORTA GOTO loop delay MOVLW 0x10 MOVWF 0x20 cyc DECFSZ 0x20 GOTO cyc RETURN END In Proteus, it won't even do anything, and in Oshonsoft's PIC Simulator, it first turns all of PORTA on at the first iteration of the loop, but then only inverts one of the bits thereafter on each iteration. Could someone tell me what I did wrong? The code is simple, and seems solid...Maybe I'm just not using COMF correctly?
__________________
<-- Feel free to IM me for random chit-chat and PIC assembly talk Proud new owner of a Cloudbook (512MB DDR2, 1.2Ghz C7-M, Windows XP Pro SP3) And PIC16 ASM purist (Who needs BASIC and C for these chips? NOT ME! |
|
|
|
|
|
|
(permalink) |
|
Maybe you need an ORG and a CONFIG line. Also, isn't port A configured as analogue by default?
Mike. |
|
|
|
|
|
|
(permalink) | |
|
Quote:
__________________
<-- Feel free to IM me for random chit-chat and PIC assembly talk Proud new owner of a Cloudbook (512MB DDR2, 1.2Ghz C7-M, Windows XP Pro SP3) And PIC16 ASM purist (Who needs BASIC and C for these chips? NOT ME! |
||
|
|
|
|
|
(permalink) |
|
You need to switch port A to digital.
Try, Code:
main BSF STATUS,5 MOVLW 0x06 ; Configure all pins MOVWF ADCON1 ; as digital inputs MOVLW 0x00 MOVWF TRISA BCF STATUS,5 Mike. Last edited by Pommie; 9th August 2007 at 06:52 AM. |
|
|
|
|
|
|
(permalink) |
|
hi,
This will run on your Oshonsoft Simulator & MPLAB, as Pommie states, you missed ADCON1 Code:
;USED WITH OSHONSOFT SIM list p=16f876A #include <p16f876A.inc> errorlevel -302, -207 __CONFIG _CP_OFF & _XT_OSC & _PWRTE_ON & _WDT_OFF & _LVP_OFF & _DEBUG_OFF main: BSF STATUS,RP0 MOVLW 0X07 MOVWF ADCON1 MOVLW 0X00 MOVWF TRISA BCF STATUS,RP0 loop: CALL delay COMF PORTA,F GOTO loop delay: MOVLW 0x10 MOVWF 0x20 cyc: DECFSZ 0x20,F GOTO cyc RETURN END Last edited by ericgibbs; 7th July 2008 at 11:21 AM. |
|
|
|
|
|
|
(permalink) |
|
You guys kick ass, thanks :-)
Update: And it even works perfectly in Proteus.
__________________
<-- Feel free to IM me for random chit-chat and PIC assembly talk Proud new owner of a Cloudbook (512MB DDR2, 1.2Ghz C7-M, Windows XP Pro SP3) And PIC16 ASM purist (Who needs BASIC and C for these chips? NOT ME! Last edited by ArtemisGoldfish; 9th August 2007 at 04:48 PM. |
|
|
|
|
|
|
(permalink) |
|
May I sugget to make a template asm file for each microcontrolle partnumber. Put every bit, flag, value, and meaning to all SFRs at the top. Pull from this template at the start of a new project and remove unessential code as desired.
Similar to this but not like this: Code:
LIST P=16F648
INCLUDE "P16F648A.INC"
INCLUDE "SHORTS.INC"
__CONFIG _LVP_OFF & _MCLRE_OFF & _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _CP_ON & _WDT_OFF & _PWRTE_OFF
ERRORLEVEL -302
CBLOCK 0X20 ; TEMPORARY STORAGE-------------
CNTJ, CNTK, CNTP1, CNTP2, CNTP3, CNT1, CNT2, W_REG, STATUS_REG
PORTB_TEMP, MS_TIME, MS_TIME_TEMP, DEB_CNT, DECOUNT
;------------THIS PROGRAM NEEDS...---------
SDELAYCOUNT
ENDC ;--------TEMPORARY STORAGE-------------
ORG 0X04
START: ;-----PORT I/O CONFIGURATION-------------------------------
BANK0
BSF CMCON, CM2 ;DISABLE COMPARATOR.
BSF CMCON, CM1
BSF CMCON, CM0
BANK1
LOADF TRISA, B'11110111'
LOADF TRISB, B'00000000'
BSF OPTION_REG, NOT_RBPU ;BCF/BSF = ENABLE/DISABLE PULL-UP.
BCF OPTION_REG, INTEDG ;BSF/BCF = HIGH/LOW - RB0/INT EDGE TRIGGER
;------POWER ON RESET CONFIGURATION--------------------------
BSF PCON, OSCF ;C/S = 37KHZ/4MHZ OSCILLATOR SPEED.
BANK1 ;------INTERRUPT CONFIGURATION-------------------------------
BCF INTCON, PEIE ;C/S = DIS/ENABLE PERIPHERAL INTERRUPTS.
BCF PIE1, TMR1IE ;C/S = DIS/ENABLE TIMER1 INTERRUPT.
BCF PIE1, CCP1IE ;C/S = DIS/ENABLE CAPTURE INTERRUPT.
BCF PIE1, CMIE ;C/S = DIS/ENABLE COMPARATOR INTERRUPT.
BCF PIE1, EEIE ;C/S = DIS/ENABLE EEPROM INTERRUPT.
BCF INTCON, GIE ;C/S = DIS/ENABLE GLOBAL INTERRUPT.
BCF INTCON, T0IE ;C/S = DIS/ENABLE TIMER0 INTERRUPT.
BANK0 ;----TIMER1 CONFIGURATION-----------------------------------
BCF T1CON, TMR1ON ;C/S = DIS/ENABLE TIMER1 ON.
BCF T1CON, TMR1CS ;C/S = IN/EXTERNAL(RA6) CLOCK.
BANK1 ;----TIMER0 CONFIGURATION-----------------------------------
BCF OPTION_REG, T0CS ;C/S = IN/EXTERNAL(RA4) CLOCK.
BCF OPTION_REG, PSA ;C/S = TIMER0/WDT PRESCALER ASSIGNMENT.
BCF OPTION_REG, .2 ;PRESCALER
BCF OPTION_REG, .1 ;000=1:2, 001=1:4, 010=1:8, 011=1:16
BCF OPTION_REG, .0 ;100=1:32, 101=1:64, 110=1:128, 111=1:256
BANK0 ;-------------------------------------------------------------
;*********MAIN**************************
CLRF PORTB
MAIN:
|
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| 555 not timing,what am I doing wrong? | markelectro | Electronic Projects Design/Ideas/Reviews | 14 | 4th August 2007 01:42 PM |
| need help modifying some pic ASM code | justDIY | Micro Controllers | 17 | 16th July 2007 11:41 AM |
| Integrating PIC ASM as a callable function from C18 | toodles | Micro Controllers | 2 | 3rd July 2007 12:01 AM |
| Circuit layout for connecting PS/2 port to a PIC? | ChemE | Electronic Projects Design/Ideas/Reviews | 11 | 25th April 2007 12:49 AM |
| Newcomers, please read! (PIC regarded) Upd. 0xD | Jay.slovak | Micro Controllers | 0 | 17th April 2005 01:04 PM |