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

#byte and #bit

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



Joined: 07 Apr 2010
Posts: 15

View user's profile Send private message

#byte and #bit
PostPosted: Sat Apr 10, 2010 10:07 am     Reply with quote

Dear all
I have 18f2550. I need to use #byte and #bit to name my pins.

My code :
Code:

#include <18F2550.h>
#use delay(clock=8000000)

#FUSES NOWDT                       //No Watch Dog Timer
#FUSES INTRC_IO                       //Internal RC Osc
#FUSES NOPROTECT                   //Code not protected from reading
#FUSES NODEBUG                     //No Debug mode for ICD
#FUSES NOLVP                       //No low voltage prgming, B3(PIC16)
#FUSES NOMCLR                        //Master Clear pin disabled


#byte PORTA=0xF80
#bit led1=PORTA.0
#bit led2=PRATA.1
#bit led3=PORTA.2

void main(void){

setup_oscillator(OSC_8MHZ); 



for(;;){

output_high(led1);
output_high(led2);
output_high(led3);

delay_ms(1000);

output_low(led1);
output_low(led2);
output_low(led3);


}

   
   }

but this code not working.

thanks
taner_73



Joined: 29 Jan 2008
Posts: 1

View user's profile Send private message ICQ Number

PostPosted: Sat Apr 10, 2010 10:45 am     Reply with quote

Hello,
first this is wrong:
Code:
#bit led2=PRATA.1

and should be:
Code:
#bit led2=PORTA.1


and second this code block:
Code:
output_high(led1);
output_high(led2);
output_high(led3);

should be:
Code:
led1=1;
led2=1;
led3=1;


and this:
Code:
output_low(led1);
output_low(led2);
output_low(led3);

should be:
Code:

led1=0;
led2=0;
led3=0;

Best regards,
Taner
Smile
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

Ttelmah
PostPosted: Sat Apr 10, 2010 12:53 pm     Reply with quote

Add, third, if you are talking directly to the pins, then _you_ have to control the TRIS.

Best Wishes
msa



Joined: 07 Apr 2010
Posts: 15

View user's profile Send private message

PostPosted: Sat Apr 10, 2010 12:56 pm     Reply with quote

Hi taner_73
Hi Ttelmah

Thanks for your answers.

It is now working.

My code after update:
Code:

#include <18F2550.h>
#use delay(clock=8000000)

#FUSES NOWDT                       //No Watch Dog Timer
#FUSES INTRC_IO                       //Internal RC Osc
#FUSES NOPROTECT                   //Code not protected from reading
#FUSES NODEBUG                     //No Debug mode for ICD
#FUSES NOLVP                       //No low voltage prgming, B3(PIC16) or
#FUSES NOMCLR                        //Master Clear pin disabled

#byte PORTA=0xF80

#bit led1=PORTA.0   // bit 0
#bit led2=PORTA.1   // bit 1
#bit led3=PORTA.2   // bit 2

void main(void){

setup_oscillator(OSC_8MHZ); 
SET_TRIS_A(0xF8); // 1111 1000
output_a(0);
for(;;){
led1=1;delay_ms(500);led1=0;
led2=1;delay_ms(500);led2=0;
led3=1;delay_ms(500);led3=0;
}
 
   }


Last edited by msa on Wed Apr 14, 2010 1:51 am; edited 1 time in total
thiam



Joined: 06 Apr 2010
Posts: 13

View user's profile Send private message

PostPosted: Sat Apr 10, 2010 8:59 pm     Reply with quote

What is difference between #bit and #byte ?
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