![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| Hey, This is my setup: Im testing my program, by puttin in DC current in RA0, RA1 and RA2. what the program is supposed to do is send an output through RB0 when there is no voltage in RA0 and RA1. It worked fine at first. But i added increased the delay time, so that RB0 would sent an output only after a certain time. with this changed code, RB0 is not sending any output. I changed back the code to the 1st one, but now PB0 doesnt send an output. I highly doubt there is anything wrong with the PIC, because i can download programs into the PIC from the computer, but i could be wrong. does anyone know wut do be happening here? | |
| |
| | (permalink) |
| Post code so we can lookie?
__________________ There\'s no graphic in my signature. I don\'t know your IP, and I\'m not trying to hax0r you. You\'re welcome. | |
| |
| | (permalink) |
| For a start I don't like the way you say "by puttin in DC current in RA0, RA1 and RA2", I hope that isn't what you really mean?, you probably already know you haven't added the attachment? (assuming there was supposed to be one?). If you're inserting source code in a post, then use the Code button on the 'Post a reply' screen, this prevents HTML destroying the formating. Just because you can program a PIC doesn't mean you haven't killed it, you may have destroyed specific I/O pins - particularly if you've put "current into them". | |
| |
| | (permalink) |
| Code: LIST P=16F877 ; Indicate to the compiler which micro to use ; Registers mem positions TRISA EQU h'85' ; PortA control regsiter TRISB EQU h'86' ; PortB control regsiter PORTA EQU h'05' ; PortA values PORTB EQU h'06' ; PortB Values STATUS EQU h'03' ; Micro Status CountM EQU h'30' ; Used for delay CountL EQU h'31' ; Used for delay ADCON1 EQU h'9F' ; Analog to digital control register (used for digital/analog control) ORG h'000' BCF STATUS,6 BCF STATUS,5 ; Make sure we're on the page 0 CLRF PORTA ; Initialize port A CLRF PORTB ; Initialize port B BSF STATUS,5 ; Change to page 1 MOVLW h'06' MOVWF ADCON1 ; Make the port A as digital input MOVLW h'FF' MOVWF TRISA ; Set all pins for PA as inputs CLRF TRISB ; Ser all pins for PB as outputs BCF STATUS,5 ; Come back to page zero ; Step 8 Reset CLRF PORTB ; Clear all the outputs ; Step 1 Start BTFSS PORTA,0 ; Check for laser 1 beam not broken GOTO PreWarn ; If broken check others ; Step 2 CALL Delay50 ; Wait some time between readings BTFSS PORTA,1 ; Check for beam L2 GOTO Alarm ; L2 Broken goto alarm (STEP 4) ; Step 3 CALL Delay50 ; Wait some time between readings BTFSS PORTA,1 ; Check for beam L3 GOTO Reset ; Reset machine (L3 broken) GOTO Start ; Goto begining (L3 not broken) ; Step 6 PreWarn CALL Delay50 CALL Delay50 ; Timer ; Check L2 BTFSS PORTA,1 GOTO HiWarn ; Goto step 7 (L2 Broken) ; Check L3 BTFSS PORTA,2 GOTO Reset ; Reset System (L3 was broken) GOTO HiWarn ; else goto step 7 right below ; Step 7 HiWarn CALL Delay50 CALL Delay50 ; 100 ms delay ; Check for both L1 and L2 broken BTFSC PORTA,0 ; This is L1 GOTO NEXT BTFSS PORTA,1 ; This is L2 GOTO Reset ; Reset system. Both broken ; else continue checking right below ; Check for both L1 = Not Broken AND L2 = Broken NEXT BTFSC PORTA,1 ; This is L2 GOTO Reset ; Reset system (the condition was not accoplished) - L2 not broken BTFSS PORTA,0 ; This is L1 GOTO Reset ; Reset system (the condition was not accoplished) - L1 broken GOTO Alarm ; Condition accoplished goto alarm (Step 4) ; Step 4 Alarm BSF PORTB,0 ; Turn on alarm!! CALL Delay50 ; Step 5 - Check for an adult command to stop alarm BTFSS PORTA,3 ; We received a command from the receiver to stop alarm?? GOTO Alarm ; Goto step 4 (we didn't recive the stop command) GOTO Reset ; Reset Micro ; Delay of 50 ms for a 4 MHz XTAL Delay50 MOVLW h'AD' MOVWF CountM MOVLW h'5F' MOVWF CountL DECFSZ CountL,F GOTO $-1 DECFSZ CountM,F GOTO $-5 RETURN END ; Program end here im sorry i didnt put in current... V dc about 5 volts each into the input pins. im using a PIC16F877 development board from futurlec. i did mess up by switching the Vcc and gnd pins from the PIC board in the begining and the power supply went into overload. but it did work fine after that. there was also an incident of static when i touched the board... dont know if that has anything to do with this.. | |
| |
| | (permalink) |
| hi parveen i have been using atmel 8052 for my projects. I just could not help you in this code. Although i will contact my friend who is best at pics. and ask about your problem abdullah NUSTIAN karachi | |
| |
| | (permalink) |
| I looked at this code briefly a few times, and each time got afraid after being lost in the countless redundant bit tests, and decided I would come back later. :P But I finally decided to make a flowchart based on your code (next time, you should make a flowchart first, and make your code based on that). It has some issues. I have highlighted the affected areas (see attachment below). 1: You say you are putting 5V DC into each of the A0, A1, and A2 inputs, and it never activates. Well, yes, according to the flowchart, after the Start, it tests A0, sees a 1, delays, tests A1, sees a 1, delays, tests A1 again, still sees a 1, and goes back to Start. So your program is behaving exactly as expected with those inputs producing no output. 2: Blue - You test A1 twice in a row. Your comments lead me to think you actually meant to test A2, but your code does A1 again. 3: Green - You test A0 twice in a row. Although there is maybe a 0.000001% chance that you could actually make that pin change states between the two tests, why test it twice? 4: Yellow - The A1 tests are mutually exclusive. The first one says if A1 is 0 then reset, otherwise continue. The second one says if A1 is 1 then reset, otherwise continue. Again, it's going to be next to impossible to switch states that fast, so this is an obvious error. 5: Why is it such a long path to get through the right side of the chart? Say that you test A0, get a zero, and wait. Then you test A1 get a 0 and wait. Why then do you test A0 and A1 two more times? While it is definitely possible for them to change states after 0.2 seconds, why test again and again, when you already just tested them? 6: I just noticed another possible mutually exclusive condition after I made the picture, so it's not colored in. The first test of A0 right after Start enters the right hand side when A0 is 0. From here, it only makes it to the Alarm section if it turns to 1 within 0.2 seconds (4 x 50ms delays). You would have to know exactly when it enters this branch of the program, and you would have to toggle it pretty darn quick if your reflexes are even that good. 7: Lastly, if you want to see if your alarm output B output will work (it should), set A0 = voltage, A1 = ground, and A3 = ground. This should allow it to enter the Alarm loop and stay there. You should be able to see the output on B0. After confirming this, change A3 to voltage. At this point the program will loop back to reset. You may see B0 briefly flicker at this point, or it may be too fast to see, but it keeps looping to Alarm and Reset. At this point put A1 = voltage. You should now be in the small loop in the left hand side of the chart that was described in issue 1. If at this point you set A0 to ground, the states it flows to are pretty much irrelevant in their present form.
__________________ There\'s no graphic in my signature. I don\'t know your IP, and I\'m not trying to hax0r you. You\'re welcome. | |
| |