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 CCS Technical Support

plc help me explain reasons about #bit

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



Joined: 05 Aug 2010
Posts: 89

View user's profile Send private message

plc help me explain reasons about #bit
PostPosted: Mon Jun 20, 2011 1:40 am     Reply with quote

hello ,guys,

I have a buzzer test program, one of them can work, but others doesn't work, they have a difference that one used the #bit syntax, pls help me analyze the reasons.

Thank you very much!

The detail info. as follow:

faulty program

#include <18f452.h>
#fuses HS,NOWDT,PUT,NOPROTECT
#use delay(CLOCK=10000000)

#define PORTA 0x5
#define PORTB 0x6
#define PORTC 0x7
#define PORTD 0X8

#bit buzzer=PORTC.1

#use fast_io(C)

void main()
{

set_tris_c(0x00);

while(1)
{
buzzer=1;
delay_us(1000);
buzzer=0;
delay_us(1000);
}
}

OK program


#include <18f452.h>
#fuses HS,NOWDT,PUT,NOPROTECT
#use delay(CLOCK=10000000)

#byte RA = 5
#byte RB = 6
#byte RC = 7
#byte RD = 8
#byte RE = 9

#define buzzer PIN_C1

void main()
{
set_tris_c(0x00);
while(1)
{
output_high(buzzer);
delay_us(1000);
output_low(buzzer);
delay_us(1000);
}
}


[/b]


Last edited by leevise on Mon Jun 20, 2011 2:40 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Mon Jun 20, 2011 2:12 am     Reply with quote

Probably nothing to do with using bit....
What is the maximum value allowed for a delay?. 100000, is _not_ legal.

Best Wishes
leevise



Joined: 05 Aug 2010
Posts: 89

View user's profile Send private message

PostPosted: Mon Jun 20, 2011 2:44 am     Reply with quote

Ttelmah wrote:
Probably nothing to do with using bit....
What is the maximum value allowed for a delay?. 100000, is _not_ legal.

Best Wishes


I have modified the delay time ,but it is also un-work , may be the ULN2003A' question? because my scheme layout is a RC0 of MCU connect the ULN2003A input pin ,and the ULN2003A output pin connect the buzzer pin ,other pin connect DC5V,
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Mon Jun 20, 2011 3:09 am     Reply with quote

Look at the data sheet. What is the address of PORTC?. It is _not_ 0x7, on an 18F452.....

Hint here. Use the compiler's SFR ability:

Code:


#byte PORTCOP=getenv("sfr:LATC")
#bit buzzer=PORTCOP.1


For _output_, on the 18 chips, it is better to write to the output latch, than directly to the port (avoids the RMW problem on the chips).

Best Wishes
leevise



Joined: 05 Aug 2010
Posts: 89

View user's profile Send private message

PostPosted: Mon Jun 20, 2011 3:22 am     Reply with quote

Ttelmah wrote:
Look at the data sheet. What is the address of PORTC?. It is _not_ 0x7, on an 18F452.....

Hint here. Use the compiler's SFR ability:

Code:


#byte PORTCOP=getenv("sfr:LATC")
#bit buzzer=PORTCOP.1


For _output_, on the 18 chips, it is better to write to the output latch, than directly to the port (avoids the RMW problem on the chips).

Best Wishes



thank you for your advice! but can you tell how to modify this un-work program ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Mon Jun 20, 2011 4:35 am     Reply with quote

Read the first line of my last post.....
leevise



Joined: 05 Aug 2010
Posts: 89

View user's profile Send private message

Thank you very much
PostPosted: Mon Jun 20, 2011 9:22 pm     Reply with quote

Ttelmah wrote:
Read the first line of my last post.....

Code:
]
#include <18f452.h>
#fuses HS,NOWDT,PUT,NOPROTECT
#use delay(CLOCK=10000000)

#byte RA = 0xF80
#byte RB = 0xF81
#byte RC = 0xF82
#byte RD = 0xF83
#byte RE = 0xF84
#bit buzzer=RC.1

#use fast_io(C) 

void main()
{
 
   set_tris_c(0x00);
 
 while(1)
 {
   buzzer=1;
    delay_us(100000);
    buzzer=0;
    delay_us(100000);
 }
 

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 21, 2011 1:21 pm     Reply with quote

Quote:
while(1)
{
buzzer=1;
delay_us(100000);
buzzer=0;
delay_us(100000);
}

You still need to download the manual and look up the allowable
parameters for this function:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf

Download the CCS manual and put it on your Windows desktop so you
can refer to it easily. Or put a shortcut on your desktop to the CCS
compiler help file. Here's the file location:
Quote:
C:\Program Files\PICC\Ccsc.chm
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