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.

Confused with this !

Status
Not open for further replies.

mnkjoi

New Member
Hey ,

Could someone helps me please with this :

Write a program that will check the input of 2-input quadruple NAND , if the NAND gate works properly then the LED connected to RD6 should be ON , otherwise the LED should be ON . Assume PORTC connected to the inputs of quadruple 2-input NAND gates , two LEDs connected to most two bits of PORTD .

Using pic assembly language .
 
Hey ,

Could someone helps me please with this :

Write a program that will check the input of 2-input quadruple NAND , if the NAND gate works properly then the LED connected to RD6 should be ON , otherwise the LED should be ON . Assume PORTC connected to the inputs of quadruple 2-input NAND gates , two LEDs connected to most two bits of PORTD .

Using pic assembly language .
Welcome to ETO, mnkjoi!

Is this a school assignment (it reads like one...)? If not, at the very least we'll need to know what are the functions of PORTs C & D and, more importantly, what is driving the PORTs.
 
Last edited:
Is it something like below? When all the 4 gates are Good, Green LED switches ON. If not Red LED switches ON?

ETO home work 1.PNG

Allen
 
Strange piece of homework where a micro is used to check if some gates work...

If this is not homework (I think it is), it is an utter ridiculous implementation. The micro should be self sufficient to solve the function by simple - if not trivial - programming.
 
Welcome to ETO, mnkjoi!

Is this a school assignment (it reads like one...)? If not, at the very least we'll need to know what are the functions of PORTs C & D and, more importantly, what is driving the PORTs.
Thanks for your reply .. No it is not school assignment .. Just a problem in the end of the chapter in an old textbook .


I read a lot about the functions of the ports and I have all the data sheets regards the PICs types . But I don't know how to write this code .

So I search for help :) .
 
Strange piece of homework where a micro is used to check if some gates work...

If this is not homework (I think it is), it is an utter ridiculous implementation. The micro should be self sufficient to solve the function by simple - if not trivial - programming.
It is not homework ... How to check the NAND gate works properly or not ?
 
while (1){
boolean working = true;

set pin1 on, set pin2 on; if input =1 then working = false
set pin1 off, set pin2 on; if input =0 then working = false
set pin1 on, set pin2 off; if input =0 then working = false
set pin1 off, set pin2 off; if input =0 then working = false
// repeat these 4 steps for each of the 4 nands

}
 
I think the definition of the testing needs to be clarified. Do we just test each individual nand gate as described in post #8 by Dr_Doggy or do we need to test for interaction between the four gates. This would involve cycling the 6 other inputs (2 for each of the other 3 gates.) through each of the 64 possible states for each one of the four tests in post #8 ?

Les
 
I think it should be sufficient for the OP to implement the table below in pic asm language.

eto NAND TESTER.PNG


When he gets better in the ASM, he can always improve the program to check for cross-talks between gates and other illegal conditions. For me, It'll be more fun to do it in 6502 or 8051 asm language.

Allen
 
Thanks absf for your help .. Your answers are highly appreciated :

I did some web searches and found that I should make a compare when I write the code . If the four nand gates outputs matching the truth table , then we say the quad two input nand gate is working properly and the GOOD LED is On . But how to compare using PIC assembly ? Comparing with which value ?



Any idea please
 
Last edited:
Read the data sheet on the PIC that you decide to use and read the instruction set summary. There are two instructions I would chose between but there are other instructions that could be used. You could test one gate at a time using a single bit comparison or you could test the four gates at the same time using a 4 bit comparison. If you don't know which values you are comparing I think you need to chose another subject. The answer has been given in one of the previous posts.

Les.
 
Is this code for one NAND is correct :


btfsc PORTC,0 ; Check bit0 in PORTC and skip next instruction if bit0 = 0 .
goto k ; This be skipped if bit0 = 0
btfsc PORTC,1 ;Check bit1 in PORTC and skip next instruction if bit1 = 0 .
goto k ; This be skipped if bit1 = 0

k
banksel PORTB
movlw 01h
movwf PORTB ; RD0 in PORTB = 1
return
 
It could be right for PART OF THE CODE depending on how the gates are connected to the I/O pins of the PIC and how you have set up the input conditions to the gate before this part of the code. It is wrong if it is wired as in the schematic in post #3

Les.
 
It could be right for PART OF THE CODE depending on how the gates are connected to the I/O pins of the PIC and how you have set up the input conditions to the gate before this part of the code. It is wrong if it is wired as in the schematic in post #3

Les.

Thanks for your prompt reply .

It is wired as in the schematic of post 3 .


I did my best and here what I wrote :




btfsc PORTC,0 ; Check bit0 in PORTC and skip next instruction if bit0 = 0 .
goto p ; This be skipped if bit0 = 0
btfsc PORTC,1 ;Check bit1 in PORTC and skip next instruction if bit1 = 0 .
goto k ; This be skipped if bit1 = 0

k

banksel PORTB ; choose PORTB
movlw 01h
movwf PORTB ; pin0 (RD0) in PORTB = 1

p

btfss PORTC,1
goto k
goto m

m
banksel PORTB
movlw 00h
movwf PORTB ; pin0 (RD0) in PORTB = 01

return

----------

It is not completed , just only for one NAND gate ... It is correct now ? If it not , then why ?
 
You have still not done one of the things that I pointed out in post #14. You seem to be setting PORTB,0 to a "1" which is not connected to anything. You also have RD0 in brackets in the comments. Is that a typing error and should be RB0 ? You are also setting PORTB,0 to a "0" in another part of the program. Think about how you would test a NAND gate. Do you know which connections on a NAND gate are inputs and outputs ?

Les,
 
You have still not done one of the things that I pointed out in post #14. You seem to be setting PORTB,0 to a "1" which is not connected to anything. You also have RD0 in brackets in the comments. Is that a typing error and should be RB0 ? You are also setting PORTB,0 to a "0" in another part of the program. Think about how you would test a NAND gate. Do you know which connections on a NAND gate are inputs and outputs ?

Les,

PORTB,0 to a '1' for one nand gate ... I should use this algorithm for the four nand gates and after that it will send a '1' to RD6 once the NAND gate works properly .
RD0 yes this typing error and it should be RB0 . :) .

I setting the PORTB to 0 if the two input in a NAND gate is 1 1 = 0 . Is this Wrong ?

The connections as shown in the post #3 . The simulation on PROTEUS is not required . I just want to write the code .

Thanks
 
1 != 0
boolean for nand is:
A*B = !C
or
!(A*B) = C

i m sorry idk asm, i program all my pic's in c, but I think it would help Les if you can elaborate how you have one nand hooked up, ie quad nand means 4 gates in package , 2input means 2-input and 1 output per gate, which nand pins are hooked up to which pic pins?
 
#include <p16f877A.inc>
org 0x00
banksel TRISC
clrf TRISC ; Make the PORTC as output
banksel PORTC
btfsc PORTC,0 ; Check bit0 in PORTC and skip next instruction if bit0 = 0 .
; goto p ; This be skipped if bit0 = 0
btfsc PORTC,1 ;Check bit1 in PORTC and skip next instruction if bit1 = 0 .
goto k ; This be skipped if bit1 = 0
k
banksel PORTD ; choose PORTD
movlw 80h
movwf PORTD


end






Here I'm trying just to make a single NAND gate with single LED ... But when I change the 0's and 1's .. The LED is still OFF . WHY ?


I even connected without NANDs the 0 and 1 directly to portc pin0 pin1 and led still OFF
 

Attachments

  • 12.jpg
    12.jpg
    255.9 KB · Views: 228
Last edited:
again i cant read asm so maybe wait for other help....but... here is a doggy guess for now!
try a second led connected to nand pin3!

Check bit0 in PORTC and skip next instruction if bit0 = 0 . <----- you do not check c0 & c1, you SET them

which part in your code do you check port D0 to find out what nand is saying?

which part in your code is the instruction that says= if D0 = 1 then D7 = 1 ???
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top