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.

cannot output porta,0 and 1 16f684

Status
Not open for further replies.

shirazmacuff

New Member
First I want to thank everyone for all the help in the past.
I’ve have now started on my pic project.
I cannot seem to get data out to pin RA0,RA1 in mpsim
I don’t know if the port is configured correctly
Here is the code
Thanks
//////////////////////////////////////////////
#define Bank0 0x00 ;
#define Bank1 0x80

;/////////////////////////////////

PORT_A_OUTPUT
banksel Bank1
clrf TRISA
return
;/////////////////////////////////
PORT_A_DIGITAL
banksel Bank1
clrf ANSEL ;analog select
return
;/////////////////////////////////
PORT_A_OUT_HIGH
call PORT_A_OUTPUT
call PORT_A_DIGITAL

banksel Bank0
bcf PORTA,0 ;not working
bcf PORTA,1 ;not working
bsf PORTA,2 ;working
bsf PORTA,4 ;working
bsf PORTA,5 ;working



return
 
What you talking about?Do you need to turn the bits PORTA 0,1 continuously?

Code:
Loop	movlw	b'00000011'	;makes portA0,1 output
	movwf	PORTA
	goto	Loop

I don't know how did you get this line for 84 chip "clrf ANSEL"
 
Last edited:
I rewrote it, but this code works fine. Hope it helps.
Code:
    list     p=16F684
    include <p16F684.inc>
    org    0
    movlw    .7    ;
    movwf    CMCON0    ; comparators off
    banksel    ANSEL    ;b1
    clrf     ANSEL     ; all digital
    clrf     TRISA   
    banksel PORTA    ;b0
    bsf PORTA,0 ;not working
    bsf PORTA,1 ;not working
    bsf PORTA,2 ;working
    bsf PORTA,4 ;working
    bsf PORTA,5 ;working    
    goto    $
    END
 
thanks for your reply Gayan
when I insert your code and i run it,
the watch window displays the following for port A
address symbol name binary
05 PORTA 00000000

i want to put 110111 in the PORTA register sothat i can light 5 LEDs
my code above gives 00110100 in the register
and your code
gives 00000000 in the register
i've tried every thing that i could think of
thanks
 
Last edited:
i'm using pick kit1
ive programmed your code.
but all leds are off??
i then added a loop
;//////////////////
list p=16F684
include <p16F684.inc>
org 0
movlw .7 ;
movwf CMCON0 ; comparators off
banksel ANSEL ;b1
clrf ANSEL ; all digital
clrf TRISA
banksel PORTA ;b0
loop
bsf PORTA,0 ;not working
bsf PORTA,1 ;not working
bsf PORTA,2 ;working
bsf PORTA,4 ;working
bsf PORTA,5 ;working
goto loop
END
;/////////////////
nothing
should i test the code on a sepperate circiut?
if that is the case, how can i light the leds on this kit

thanks
 
Hi,
You can't do this:
Code:
bsf PORTA,0 ;not working
bsf PORTA,1 ;not working
bsf PORTA,2 ;working
bsf PORTA,4 ;working
bsf PORTA,5 ;working
Even this is bit oriented instruction, but the PIC will read the whole port, modify the particular bit, and write back to the port. One instruction cycle is not enough for the bit to be changed sometimes. When the second modification of the port, the last written bit may not be valid.
 
hi guys
i know there is nothing wrong with the code because it works in mpsim
but when i program the device, the leds are dead.
does anyone know which pins are connected to the leds on the pickkit 1 development board?


after programming , mp lab says "program succeeded".
how would i go about troubleshooting this problem.

thanks again for all replies.
this board in invaluable for those of us with limited recources
 
The LEDs in the PICkit1 are charlieplexed just like the Junebugs (my kit).
The PICkit1 code from the book 123 PIC Experiments by Myke Predko.
**broken link removed**
Code:
 title  "asmPKLED 3 - PICkit Running LED"
;
;  This program copies the operation of cPKLED.c and Flashes the 8 LEDs
;   on the PICkit 1 PCB in Sequence by Storing the Values for the LEDs 
;   and the TRIS registers in Arrays
;
;  Hardware Notes:
;   PIC16F684 running at 4 MHz Using the Internal Clock
;   Circuit Runs on PICkit 1 PCB
;  
;  Original Code:
; 
;  int i, j, k;
;  char LEDValue[8]  = {0b010000, 0b100000, 0b010000, 0b000100, 
;                       0b100000, 0b000100, 0b000100, 0b000010};
;  char TRISValue[8] = {0b001111, 0b001111, 0b101011, 0b101011, 
;                       0b011011, 0b011011, 0b111001, 0b111001};
;  
;  main()
;  {
;  
;      PORTA = 0;
;      CMCON0 = 7;                 //  Turn off Comparators
;      ANSEL = 0;                  //  Turn off ADC
;  
;      k = 0;                      //  Start at LED 0
;  
;      while(1 == 1)               //  Loop Forever
;      {
;          for (i = 0; i < 255; i++)  //  Simple Delay Loop
;              for (j = 0; j < 129; j++);
;
;          PORTA = LEDValue[k];    //  Specify LED Output
;          TRISA = TRISValue[k];
;  
;         k = (k + 1) % 8;        //  Increment k within range of 0-7
;  
;      }  //  elihw
;  }  //  End cPKLED
; 
;
;
;  Myke Predko
;  04.11.07
;
  LIST R=DEC
 INCLUDE "p16f684.inc"

 __CONFIG _FCMEN_OFF & _IESO_OFF & _BOD_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTOSCIO

;  Variables
 CBLOCK 0x20
LEDValue:8, TRISValue:8
Dlay
k
 ENDC

  PAGE
;  Mainline of asmPKLED

 org     0

  nop                           ;  For ICD Debug

  clrf    PORTA                 ;  Initialize I/O Bits to Off
  movlw   7                     ;  Turn off Comparators
  movwf   CMCON0
  bsf     STATUS, RP0
  clrf    ANSEL ^ 0x80          ;  All Bits are Digital
  bcf     STATUS, RP0

  clrf    k                     ;  Start with D0

  movlw   b'010000'              ;  Load LEDValue Explicitly
  movwf   LEDValue
  movlw   b'100000'
  movwf   LEDValue + 1
  movlw   b'010000'
  movwf   LEDValue + 2
  movlw   b'000100'
  movwf   LEDValue + 3
  movlw   b'100000'
  movwf   LEDValue + 4
  movlw   b'000100'
  movwf   LEDValue + 5
  movlw   b'000100'
  movwf   LEDValue + 6
  movlw   b'000010'
  movwf   LEDValue + 7
  movlw   b'001111'             ;  Load TRISValue Explicitly
  movwf   TRISValue
  movwf   TRISValue + 1         ;  NOTE: LEDs are in Pairs
  movlw   b'101011'
  movwf   TRISValue + 2
  movwf   TRISValue + 3
  movlw   b'011011'
  movwf   TRISValue + 4
  movwf   TRISValue + 5
  movlw   b'111001'
  movwf   TRISValue + 6
  movwf   TRISValue + 7

Loop:                           ;  Return Here after Delay and RB0 Toggle

  clrf    Dlay                  ;  High 8 Bits for Delay
  clrw
  goto    $ + 1
  goto    $ + 1
  addlw   -1                    ;  Decrement the contents of WREG
  btfss   STATUS, Z             ;   256x
   goto   $ - 4
  decfsz  Dlay, f               ;  Repeate 255x
   goto   $ - 6

;  PORTA = LEDValue[k]
  movf    k, w                  ;  Load the Offset for LEDValue
  addlw   LEDValue              ;  Add to Start of LEDValue Array
  movwf   FSR                   ;  Store Address in Index Register
  movf    INDF, w               ;  Get LEDValue[k]
  movwf   PORTA                 ;  Save in PORTA Register

;  TRISA = TRISValue[k]
  movf    k, w                  ;  Get the Offset for TRISValue
  addlw   TRISValue             ;  Add to the Start of Array
  movwf   FSR                   ;  Store Address in Index Register
  movf    INDF, w               ;  Get TRISValue[k]
  bsf     STATUS, RP0           ;  Save in TRISA Register
  movwf   TRISA ^ 0x80
  bcf     STATUS, RP0

  incf    k, w                  ;  Increment the Active LED
  andlw   7                     ;  Keep Within range of 0-7
  movwf   k

  goto    Loop                  ;  Repeat


  end
 
I am confused, Bill!!

where is CMCON in F84 instruction set? Of course I am watching F84A instruction set. from datasheet DS35007B

P S: OK sorry

It is F684-- got it
 
Last edited:
thanks bill
code work in mpsim and on the board
now i will study the code , and see if i can understand how it works

many thanks everyone
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top