View previous topic :: View next topic |
Author |
Message |
leevise
Joined: 05 Aug 2010 Posts: 89
|
plc help me explain reasons about #bit |
Posted: Mon Jun 20, 2011 1:40 am |
|
|
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: 19518
|
|
Posted: Mon Jun 20, 2011 2:12 am |
|
|
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
|
|
Posted: Mon Jun 20, 2011 2:44 am |
|
|
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: 19518
|
|
Posted: Mon Jun 20, 2011 3:09 am |
|
|
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
|
|
Posted: Mon Jun 20, 2011 3:22 am |
|
|
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: 19518
|
|
Posted: Mon Jun 20, 2011 4:35 am |
|
|
Read the first line of my last post..... |
|
|
leevise
Joined: 05 Aug 2010 Posts: 89
|
Thank you very much |
Posted: Mon Jun 20, 2011 9:22 pm |
|
|
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
|
|
Posted: Tue Jun 21, 2011 1:21 pm |
|
|
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
|
|
|
|
|