View previous topic :: View next topic |
Author |
Message |
piedos
Joined: 14 Mar 2005 Posts: 5 Location: TURKEY/Ankara
|
need help...an easy problem |
Posted: Sat Apr 16, 2005 7:46 pm |
|
|
#include <16F628A.h>
#byte PORTB=0x06
#define solbas PIN_B0
void main()
{
set_tris_b(0);
while(1)
{
if(solbas == 0)
PORTB=255;
}
}
and the list,
ROM used: 13 words (1%)
Largest free fragment is 2035
RAM used: 5 (3%) at main() level
5 (3%) worst case
Stack: 0 locations
*
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 004
0003: NOP
.................... #include <16F628A.h>
.................... //////// Standard Header file for the PIC16F628A device ////////////////
.................... #device PIC16F628A
.................... #list
....................
.................... #byte PORTB=0x06
.................... #define solbas PIN_B0
....................
....................
....................
....................
....................
.................... void main()
.................... {
0004: CLRF 04
0005: MOVLW 1F
0006: ANDWF 03,F
0007: MOVLW 07
0008: MOVWF 1F
.................... set_tris_b(0);
0009: MOVLW 00
000A: TRIS 6
.................... while(1)
.................... {
.................... if(solbas == 0)
.................... PORTB=255;
.................... }
000B: GOTO 00B
.................... }
....................
000C: SLEEP
as you see microcontroller enters infinite loop without making PORTB all high, i think if(solbas == 0) does not work,
i need your comments,
thanx in advance _________________ ---------------------------------------------------------
The only thing that equally given mankind is time. |
|
|
future
Joined: 14 May 2004 Posts: 330
|
|
Posted: Sat Apr 16, 2005 8:18 pm |
|
|
There is a logic error there, you are setting portb but reading b0 and expecting it to be 0.
Port logic levels are unknown at startup. |
|
|
Felix Althaus
Joined: 09 Sep 2003 Posts: 67 Location: Winterthur, Switzerland
|
|
Posted: Sun Apr 17, 2005 3:21 am |
|
|
Hello
if(solbas == 0)
solbas is defined as PIN_B0 and PIN-B0 is defined as a constant value in the header file (look at it). S you'r comparing a const to another one, with the never changing result FALSE. And the compiler optimizes that away.
What you want to use is:
if(input(solbas) == 0)
Felix |
|
|
sh1
Joined: 04 Mar 2005 Posts: 5
|
|
Posted: Sun Apr 17, 2005 7:50 am |
|
|
I just don't understand one thing... If you're setting Port B as Output, why are you reading Input from it?
Also, like Felix Althaus said, if you're really interested in reading Input, you missed that input() function. |
|
|
Felix Althaus
Joined: 09 Sep 2003 Posts: 67 Location: Winterthur, Switzerland
|
|
Posted: Sun Apr 17, 2005 8:25 am |
|
|
Hi
I agree, the setup_tris_b(0) is wrong if you want to use the pin as an input. But that isn't your problem, because unless you'r using fast_io (which you don't) the compiler handles the tris bits automatically. But only if you use the input() function
Felix |
|
|
piedos
Joined: 14 Mar 2005 Posts: 5 Location: TURKEY/Ankara
|
|
Posted: Sun Apr 17, 2005 10:19 am |
|
|
thank u, Felix,sh1 and future
i've understand..
--->knowledge grow up as you share _________________ ---------------------------------------------------------
The only thing that equally given mankind is time. |
|
|
|