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.

code help

Status
Not open for further replies.

emaney

New Member
i real need somones help with this pic16f84a question
A de-multiplexer has an input line, pinRB0, and four output
lines, output0 to output3, which are, respectively, the pins RA0-RA3. the
demultiplexer copies the digital signal appearing on the input line on to one of
the four output lines. The output line is selected by a two bit
selection code input on the pins RB1 and RB2.

i have this code that does the following
The following program, in assembly language of the pic16f84A microcontroller, configures the three
; lower pins of PORTA(RA0, RA1 and RA2) as inputs, and the pins of PORTB as output. The program then
;enters a non-terminating loop. in the loop program read the three input lines, interpret the input as
;a 3 bit binary value(RA0 as the least significant bit), and make PORTB line corresponding to the
;input value 'on' by outputting the value '1' on this line.
;All other output lins must remain '0'.
#DEFINE PAGE0 BCF 0x03,5
#DEFINE PAGE1 BSF 0x03,5

PCL: EQU 0x02
STATUS: EQU 0x03
PORTA: EQU 0x05
TRISA: EQU 0x05
PORTB: EQU 0x06
TRISB: EQU 0x06

W: EQU 0
F: EQU 1

ORG 0x0
goto MAIN
org 5

MAIN:
clrf PORTA
clrf PORTNB
PAGE1
movlw B'00000111'
iorwf TRISA,F ;RA0-RA2 as input
clrf TRISB ;Port B0-B7 as output
PAGE0

LOOPX:
movf PORTA. W
andlw B'00000111'
call TABLE
movfw PORTB
goto LOOPX

TABLE:
addwf PCL, F
retlw B'00000001'
retlw B'00000010'
retlw B'00000100'
retlw B'00001000'
retlw B'00010000'
retlw B'00100000'
retlw B'01000000'
retlw B'10000000'
END

after goign through this code anybody can tell me how can code teh above question(can anybody the code so it does what i asked at the top)

i just hope iam clear enough.....please if u can send resoponse to my email:pktdksk@yahoo.com.au
 
i real need somones help with this pic16f84a question
A de-multiplexer has an input line, pinRB0, and four output
lines, output0 to output3, which are, respectively, the pins RA0-RA3. the
demultiplexer copies the digital signal appearing on the input line on to one of
the four output lines. The output line is selected by a two bit
selection code input on the pins RB1 and RB2.

My PIC assembly is little rusty right now, but here goes a hint (untested)

Code:
loop:

  ;get the output selector
  movf PORTB,w
  rrf WREG
  andlw B'00000011'

  ;convert 0-3 to bit-mask
  call table
  movwf Mask

  ;switch all zeroes to ones in mask and vice versa
  xorlw B'11111111',w

  ;read all the bits of PORTA but the selected one (leave it clear)
  andwf PORTA,w

  ;if PORTB.0 is set, set also selected output in PORTA
  btfsc PORTB,0
  orwf Mask,w

  ;write modified value back to PORTA
  movwf PORTA
  goto loop  

table:

  addwf PCL,F
  retlw B'00000001'
  retlw B'00000010'
  retlw B'00000100'
  retlw B'00001000'

Disadvantage: if interrupt changes PORTA between andwf PORTA,w and movwf PORTA, the change will be reversed by this code.
 
orwf Mask,w....................little confused about this, gives error as well. iam still confused about it?
 
emaney said:
orwf Mask,w....................little confused about this, gives error as well. iam still confused about it?

This was just a hint a not a working code, I did not actually test it. The instruction that does not compile I meant IORWF - inclusive OR
 
dipmicro said:
My PIC assembly is little rusty right now, but here goes a hint (untested)

Code:
loop:

  ;get the output selector
  movf PORTB,w
  rrf WREG
  andlw B'00000011'

  ;convert 0-3 to bit-mask
  call table
  movwf Mask

  ;switch all zeroes to ones in mask and vice versa
  xorlw B'11111111',w

  ;read all the bits of PORTA but the selected one (leave it clear)
  andwf PORTA,w

  ;if PORTB.0 is set, set also selected output in PORTA
  btfsc PORTB,0
  orwf Mask,w

  ;write modified value back to PORTA
  movwf PORTA
  goto loop  

table:

  addwf PCL,F
  retlw B'00000001'
  retlw B'00000010'
  retlw B'00000100'
  retlw B'00001000'

Disadvantage: if interrupt changes PORTA between andwf PORTA,w and movwf PORTA, the change will be reversed by this code.

this program does not have to be interrupt driven......How do i define the input and output channel selection code......
 
please could anyone giv help on this, because the loop iam not understanding. if someone can just give pseudocode, because iam not sure how i can write up the code for the given question
 
ok i know iam askign too much but i realy need someonce to help me with the above code, i have exam on thursday and i have to do this code to practice for the exam..........please
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top