Hi, Dear roelof 't Hooft :
Sorry to bug you again. I think why the code doesn't work has much to do
with the 2 red bold lines:
#include <reg51.h>
*sbit Beep = P1^5 ; *
unsigned char n=0;
unsigned char code music_tab[] ={
0x18, 0x30, 0x1C , 0x10,
0x20, 0x40, 0x1C , 0x10,
0x18, 0x10, 0x20 , 0x10,
0x1C, 0x10, 0x18 , 0x40,
0x1C, 0x20, 0x20 , 0x20,
0x1C, 0x20, 0x18 , 0x20,
0x20, 0x80, 0xFF , 0x20,
0x30, 0x1C, 0x10 , 0x18,
0x20, 0x15, 0x20 , 0x1C,
0x20, 0x20, 0x20 , 0x26,
0x40, 0x20, 0x20 , 0x2B,
0x20, 0x26, 0x20 , 0x20,
0x20, 0x30, 0x80 , 0xFF,
0x20, 0x20, 0x1C , 0x10,
0x18, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x20, 0x1C , 0x10,
0x18, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x20, 0x15 , 0x20,
0x1C, 0x20, 0x20 , 0x20,
0x26, 0x40, 0x20 , 0x20,
0x2B, 0x20, 0x26 , 0x20,
0x20, 0x20, 0x30 , 0x80,
0x20, 0x30, 0x1C , 0x10,
0x20, 0x10, 0x1C , 0x10,
0x20, 0x20, 0x26 , 0x20,
0x2B, 0x20, 0x30 , 0x20,
0x2B, 0x40, 0x20 , 0x15,
0x1F, 0x05, 0x20 , 0x10,
0x1C, 0x10, 0x20 , 0x20,
0x26, 0x20, 0x2B , 0x20,
0x30, 0x20, 0x2B , 0x40,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x20, 0x15 , 0x20,
0x1C, 0x20, 0x20 , 0x20,
0x26, 0x40, 0x20 , 0x20,
0x2B, 0x20, 0x26 , 0x20,
0x20, 0x20, 0x30 , 0x30,
0x20, 0x30, 0x1C , 0x10,
0x18, 0x40, 0x1C , 0x20,
0x20, 0x20, 0x26 , 0x40,
0x13, 0x60, 0x18 , 0x20,
0x15, 0x40, 0x13 , 0x40,
0x18, 0x80, 0x00
};
void int0() interrupt 1
{ TH0=0xd8;
TL0=0xef;
n--;
}
void delay (unsigned char m)
{
unsigned i=3*m;
while(--i);
}
void delayms(unsigned char a)
{
while(--a);
}
void main()
{ unsigned char p,m;
unsigned char i=0;
TMOD&=0x0f;
TMOD|=0x01;
TH0=0xd8;TL0=0xef;
IE=0x82;
play:
while(1)
{
a: p=music_tab[i];
if(p==0x00) { i=0, delayms(1000); goto play;}
else if(p==0xff) { i=i+1;delayms(100),TR0=0; goto a;}
else {m=music_tab[i++], n=music_tab[i++];}
TR0=1;
while(n!=0) *Beep = ~Beep*,delay(m);
TR0=0;
}
}
The above code is working, but in order to be able to be compiled with
sdcc,what I've done is :
1) remove the first red line,
2) change the 2nd red line from *Beep=~Beep* to *P1_5=~P1_5* ; which seems
to be incorrect.
I myself of course supports ANSI C, instead of Keil C. However, I've
already met so much such situations in Keil C
code. How can I solve such problems in a uniform way in sdcc?
Thank you very much...
Cheers
On Sat, Jun 8, 2013 at 6:04 PM, JIA Pei <jp4w...@gmail.com> wrote:
>
> Hi, roelof
>
> Thank you very much for your prompt reply. Seriously thank you.
> The code is actually copied from somebody else. I just did some
> copy/paste, and then test.
>
> I responded to my previous Email, probably into the wrong Email address
> (the sdcc development,
> instead of sdcc user) . Sorry. I'm trying your solution now...
>
> Thank you
> *
> *
> *
> *
> *JIA Pei <jp4w...@gmail.com>*
> *9:54 AM (8 hours ago)*
> **
> **
> **
> *to Development*
> **
> *Thank you for all who have answered my questions !! seriously thank
> you. *
> *The solutions has been found:*
> *
> *
> *
> *
> *
> *
> *#include <8052.h>*
> *
> *
> *#define RELAY P1_4*
> *#define K1 P2_7*
> *
> *
> *main()*
> *{*
> *while(1)*
> *{*
> * if (!K1) RELAY = 0;*
> * else RELAY = 1;*
> *}*
> *}*
> *
> *
> *
> *
> *Thank you everybody !!!*
>
>
>
>
>
> On Sat, Jun 8, 2013 at 5:48 PM, roelof 't Hooft <roel...@itholland.nl>wrote:
>
>> On Sat, 2013-06-08 at 17:15 +0800, JIA Pei wrote:
>>
>> > #include <reg51.h>
>>
>> Did you read the replies on your previous post ?
>> You did not respond to them (yet).
>> Hint : sdcc must be giving you a warning about
>> NOT using reg51.h
>>
>>
>> > void int0() interrupt 1
>> > { TH0=0xd8;
>> > TL0=0xef;
>> > n--;
>> > }
>>
>> The proper setup of the interrupt routine with a current
>> sdcc version is like the following :
>>
>> void Timer0_ISR(void) __interrupt tf0_vector
>> {
>> ....;
>> }
>>
>> tf0_vector can be replaced with a number if you like as it
>> already is a number set with #define in the processor type
>> header file.
>>
>>
>> > void delay (unsigned char m)
>> > {
>> > unsigned i=3*m;
>>
>> This variable is unsigned type what ?
>> I am assuming integer due to the three times multiplication
>> of a char (max value 255 * 3).
>>
>>
>> > void delayms(unsigned char a)
>> > {
>> > while(--a);
>> > }
>>
>> If you want strict timing, like a millisecond delay, use
>> a hardware timer.
>>
>>
>> > play:
>> > while(1)
>> > {
>> > a: p=music_tab[i];
>> > if(p==0x00) { i=0, delayms(1000); goto play;}
>>
>> A "goto", seriously ?
>>
>> Still no mention of the sdcc version.......
>> And no specific errors noted that sdcc gave.
>>
>> roelof
>>
>> ps: advise : please clean up your code writing skills. It
>> looks like s**t.
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> How ServiceNow helps IT people transform IT departments:
>> 1. A cloud service to automate IT design, transition and operations
>> 2. Dashboards that offer high-level views of enterprise services
>> 3. A single system of record for all IT processes
>> http://p.sf.net/sfu/servicenow-d2d-j
>> _______________________________________________
>> Sdcc-user mailing list
>> Sdcc-user@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/sdcc-user
>>
>
>
>
> --
>
> Pei JIA
>
> Email: jp4w...@gmail.com
> cell: +1 604-362-5816
>
> Welcome to Vision Open
> http://www.visionopen.com
>
--
Pei JIA
Email: jp4w...@gmail.com
cell: +1 604-362-5816
Welcome to Vision Open
http://www.visionopen.com
------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user