CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

need help...an easy problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
piedos



Joined: 14 Mar 2005
Posts: 5
Location: TURKEY/Ankara

View user's profile Send private message Send e-mail ICQ Number

need help...an easy problem
PostPosted: Sat Apr 16, 2005 7:46 pm     Reply with quote

#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

View user's profile Send private message

PostPosted: Sat Apr 16, 2005 8:18 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Apr 17, 2005 3:21 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Apr 17, 2005 7:50 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Apr 17, 2005 8:25 am     Reply with quote

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

View user's profile Send private message Send e-mail ICQ Number

PostPosted: Sun Apr 17, 2005 10:19 am     Reply with quote

thank u, Felix,sh1 and future
i've understand..

--->knowledge grow up as you share
_________________
---------------------------------------------------------
The only thing that equally given mankind is time.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group