Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

something missing?

Status
Not open for further replies.

hjl4

Member
Please look over this bit of code, and tell me why LED will not flash on every pin, except of cours MCLR.

Thanks
Code:
list      p=16f88           ; list directive to define processor
	#include <p16F88.inc>        ; processor specific variable definitions

	errorlevel  -302              ; suppress message 302 from list file

	__CONFIG    _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_IO
	__CONFIG    _CONFIG2, _IESO_OFF & _FCMEN_OFF

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.




;***** VARIABLE DEFINITIONS
D1       EQU     0x71        ; variable used for context saving 
D2   EQU     0x72        ; variable used for context saving
pclath_temp   EQU     0x73	  ; variable used for context saving





;**********************************************************************
	ORG     0x000             ; processor reset vector
	goto    INIT             ; go to beginning of program
	
INIT

   BANKSEL PORTA ;select bank of PORTA (BANK 0)
   CLRF PORTA    ;initialize PORTA by clearing output data latches
   
   BANKSEL ANSEL ;select bank of ANSEL (BANK 1)
   MOVLW 0X00    ; 1= analogue pins, 0= digital pins    
   MOVWF ANSEL   ; configure all pins as digital I/O
   MOVLW 0X20    ; value used to initialize data direction (RA5 is input only, thefore bit 6 is 1, or 20h).
   MOVWF TRISA   ; set RA0-RA4 as digital output, RA5 as MCLR input only, RA6 and RA7 as digital output.
   
   BANKSEL PORTB ;select bank of PORTB (BANK 0)
   CLRF PORTB    ;clear PORTB data latches
   BANKSEL TRISB ;select bank of TRISB (BANK 1)
   MOVLW 0X00    ;value used to initialize data direction 1= input, 0= output.
   MOVWF TRISB   ;make all pins outputs
   BANKSEL TRISB
   
   
  
  
   


    MOVLW 0XFF
    MOVWF PORTA
    MOVWF PORTB
    
MAIN
    NOP
    NOP
    NOP
    NOP
    NOP
    XORWF PORTA,1
    XORWF PORTB,1
    CALL DELAY
    GOTO MAIN
    
    
    
    
    
DELAY

    DECFSZ D1,1
    GOTO DELAY
    DECFSZ D2,1
    GOTO DELAY
    RETURN
        

; remaining code goes here



; initialize eeprom locations

	ORG	0x2100
	DE	0x00, 0x01, 0x02, 0x03


	END                       ; directive 'end of program'
 
IIRC, the 16F88 has analog inputs enabled by default after a reset. Try clearing your ANSEL register to make all of your analog pins into digital I/O.
 
On the same token, make sure your comparators are disabled. I don't remember off hand if they are enabled by default.
 
i'm not sure, but try this:

cblock the D1 and D2 to the address to be saved, then u need to give them (D1 and D2) value.

maybe i'm wrong, still newbie in pic
 
Thanxs phalanx

But as you can see, I have already made PortA all digital, and there is no further resetting taking place.
As for comparators, they are supposed to be disabled by default, (if I read the datasheet right).
I'm stumped again by this chip.
 
I think it is a careless mistake.

MOVWF TRISB ;make all pins outputs
BANKSEL TRISB ;<<<<<<<<<<<

MOVLW 0XFF
MOVWF PORTA ;<<<<<<<<<<< Oh dear !!!! Wrong bank !!!
MOVWF PORTB
 
Your're right. I missed that in your code.

Another thing I just caught is your very last BANKSEL command leaves you in bank 1. In order to drive PORTA or PORTB, you have to be in BANK 0. Your D1 and D2 variables should be OK because they are in access RAM.
 
hjl4 said:
As for comparators, they are supposed to be disabled by default, (if I read the datasheet right).

If the other suggestions don't work, I'd try explicitly disabling them. I've been bitten by default-enabled comparators more times than I care to remember, and I pretty much always explicitly disable them now just to be safe.
 
why they are different with what i know:
Code:
bsf  STATUS,RP0      ;select bank 1
clrw
movwf   trisb     ;set port b all output
movwf   trisa     ;set port a all output
bcf  STATUS,RP0     ;select bank 0

.
.
.
movlw   0xff
movwf  PORTB     ;portb high
 
Ok so I've tried everything else, and in sim mode (MPLAB), it works, so I'm left with electronics.
I have VDD +5V vss to gnd PIN RA5
to VDD.
What else is missing?
OH and LEDs on I/O pins.
 
bananasiong said:
why they are different with what i know:

When his code enters the "Main" loop the W register, PORTA, and PORTB are already loaded with 0xFF. The loop XORs Wreg with PORTA and PORTB and stores the result back to the port registers. In the first cycle, 0xFF is XORed with 0xFF which results in 0x00. When stored in the port registers, it shuts the LEDs off. On the second pass through the Main loop, 0xFF is XORed with 0x00 wich results in 0xFF. When stored in the port registers, it turns the LEDs on.

The program relies on the fact that the neither the Main loop nor the delay routine thrash the value in the Wreg. For a small program like this, it is perfectly acceptable. Larger programs should reload the Wreg at each loop iteration just to be safe.
 
Last edited:
Thanks i got it now. didn't read the code clearly.
but i don't know about banksel. Is it used to select bank?
 
hjl4 said:
Ok so I've tried everything else, and in sim mode (MPLAB), it works, so I'm left with electronics.
I have VDD +5V vss to gnd PIN RA5
to VDD.
What else is missing?
OH and LEDs on I/O pins.

In your configuration bits, you have turned MCLR off which makes RA5 an I/O pin. You should not tie VDD directly to it because you are effectively shorting the power supply to ground when the pin toggles low. There are current limiting components in the I/O port but you can still put considerable stress on it.

Even if you are using MCLR, Microchip does not recommend directly connecting it to Vdd. Page 133 of the datasheet has the the recommended connections.
 
You're right about MCLR phalanx,
This is revised code
The delay was so long, 20seconds, that I should of been more patient.
It worked all along.
Thanks everyone.



Code:
;***** VARIABLE DEFINITIONS
D1       EQU     0x71        ; variable used for context saving 
D2   EQU     0x72        ; variable used for context saving
pclath_temp   EQU     0x73	  ; variable used for context saving





;**********************************************************************
	ORG     0x000             ; processor reset vector
	goto    INIT             ; go to beginning of program
	
INIT

   BANKSEL PORTA ;select bank of PORTA (BANK 0)
   CLRF PORTA    ;initialize PORTA by clearing output data latches
   
   BANKSEL ANSEL ;select bank of ANSEL (BANK 1)
   MOVLW 0X00    ; 1= analogue pins, 0= digital pins    
   MOVWF ANSEL   ; configure all pins as digital I/O
   MOVLW 0X20    ; value used to initialize data direction (RA5 is input only, thefore bit 6 is 1, or 20h).
   MOVWF TRISA   ; set RA0-RA4 as digital output, RA5 as MCLR input only, RA6 and RA7 as digital output.
   
   BANKSEL PORTB ;select bank of PORTB (BANK 0)
   CLRF PORTB    ;clear PORTB data latches
   BANKSEL TRISB ;select bank of TRISB (BANK 1)
   MOVLW 0X00    ;value used to initialize data direction 1= input, 0= output.
   MOVWF TRISB   ;make all pins outputs
   BCF STATUS, RP0
   
   
  
  
   

    
   
    MOVLW 0XFF
   
    
MAIN
    NOP
    NOP
    NOP
    NOP
    NOP
    XORWF PORTA,1
    XORWF PORTB,1
    CALL DELAY
    GOTO MAIN
    
    
    
    
    
DELAY

    DECFSZ D1,1
    GOTO DELAY
    DECFSZ D2,1
    GOTO DELAY
    RETURN
        

; remaining code goes here



; initialize eeprom locations

	ORG	0x2100
	DE	0x00, 0x01, 0x02, 0x03


	END                       ; directive 'end of program'
 
phalanx said:
In your configuration bits, you have turned MCLR off which makes RA5 an I/O pin. You should not tie VDD directly to it because you are effectively shorting the power supply to ground when the pin toggles low. There are current limiting components in the I/O port but you can still put considerable stress on it.

I wish I could toggle RA5 low. It is not an I/O pin but an input pin only. :)
 
eblc1388 said:
I wish I could toggle RA5 low. It is not an I/O pin but an input pin only. :)

That would certainly make it difficult to sink current wouldn't it? :D

Maybe I should RTFM again! As far as I can remember, I have always left the MCLR pin active on all my designs so I've never ran into that trouble!
 
Status
Not open for further replies.

Latest threads

Back
Top