ATMEL 89C52 Programming

8051, AVR, ARM, ISP programmer, multi processor communication, embedded C...

Moderators: ikalogic, cotto88

ATMEL 89C52 Programming

Postby ssm14293 » Thu Feb 03, 2011 9:31 pm

Please tell me whats wrong with the code.


1 #include <REGX52.H> //header for 89C52
2 #define SWTV P1_0 //defines P1.0 as SW_TV
3 #define SWLITE P1_1 //defines P1.1 as SW_LITE
4 #define SWHID P1_2 //defines P1.2 as SW_HID
5 #define SWLOCK P1_3 //defines P1_3 as SW_LOCK
6 #define TVC1 P2_0 //defines P2.0 as TV_C1
7 #define LITEC2 P2_1 //defines P2.1 as LITE_C2
8 #define HIDC3 P2_2 //defines P2.2 as HID_C3
9 #define LOCKC4 P2_3 //defines P2.3 as LOCK_C4
10 #define TVLED P0_1 //defines P0.1 as TV_LED
11 #define LITELED P0_2 //defines P0.2 as LITE_LED
12 #define HIDLED P0_3 //defines P0.3 as HID_LED
13 #define LOCKLED P0_4 //defines P0.4 as LOCK_LED
14 #define ERRORSPK P0_5 //defines P0.5 as ERRORSPK
15
16 unsigned int i;
17
18 bit a, b, c, d; //declares bit variable a,b,c,d
19
20 void main ()
21 {
22 P0 = 0x00; //initial port setting
23 P1 = 0xff;
24 P2 = 0xff;
25 P3 = 0xff;
26
27 if (SWTV == 1){
28 a = 1;
29 }elseif ( a == 1) & ( SWTV == 1){
29 TVC1 = 0;
30 }elseif ( a == 1) & ( b == 1 | c == 1 | d == 1 ){
31 TVC1 = 0;
32 ERRORSPK = 1;
33 delay_100ms;
34 ERRORSPK = 0;
35 delay_100ms;
36 ERRORSPK = 1;
37 delay_100ms;
38 ERRORSPK = 0;
39 delay_100ms;
40 ERRORSPK = 1;
41 delay_100ms;
42 ERRORSPK = 0;
43 }
44 }else{
45 TVC1 = 1;
46 }


in getting these errors:
G.NOMATE.C(29): warning C206: 'elseif': missing function-prototype
G.NOMATE.C(29): error C267: 'elseif': requires ANSI-style prototype
G.NOMATE.C(29): error C141: syntax error near '{'
G.NOMATE.C(31): error C141: syntax error near '{'
G.NOMATE.C(34): error C202: 'delay_100ms': undefined identifier
G.NOMATE.C(36): error C202: 'delay_100ms': undefined identifier
G.NOMATE.C(38): error C202: 'delay_100ms': undefined identifier
G.NOMATE.C(40): error C202: 'delay_100ms': undefined identifier
G.NOMATE.C(42): error C202: 'delay_100ms': undefined identifier
G.NOMATE.C(45): error C141: syntax error near 'else'
G.NOMATE.C(46): error C231: 'P2_0': redefinition
G.NOMATE.C(46): error C231: 'P2_0': redefinition
G.NOMATE.C(47): error C141: syntax error near '}'
// ZacK ValentinE \\
ssm14293
 
Posts: 10
Joined: Thu Feb 03, 2011 8:13 pm

Re: ATMEL 89C52 Programming

Postby ikalogic » Fri Feb 04, 2011 10:46 pm

are you sure you are compiling this as a C code, not as assembly ..2683
True wisdom is knowing what you don't know -- Confucius
User avatar
ikalogic
Site Admin
 
Posts: 2236
Joined: Wed Jan 02, 2008 2:00 pm
Location: Limoges, France

Re: ATMEL 89C52 Programming

Postby ssm14293 » Sat Feb 05, 2011 5:34 pm

yes its C.
im a newbie...
and i WAS using uVision...
now im using MikroC for 8051
i jus wana kno how to give high to P0.026832683
is this correct:
P0 = 0x80
or im doing the other way round26832683
thanx for your reply...
awaiting help...
ssm14293
 
Posts: 10
Joined: Thu Feb 03, 2011 8:13 pm

Re: ATMEL 89C52 Programming

Postby ikalogic » Sat Feb 05, 2011 5:51 pm

ssm14293 wrote:yes its C.
im a newbie...
and i WAS using uVision...
now im using MikroC for 8051
i jus wana kno how to give high to P0.026832683
is this correct:
P0 = 0x80
or im doing the other way round26832683
thanx for your reply...
awaiting help...


No, P0 = 0x01; is correct way :)
True wisdom is knowing what you don't know -- Confucius
User avatar
ikalogic
Site Admin
 
Posts: 2236
Joined: Wed Jan 02, 2008 2:00 pm
Location: Limoges, France

Re: ATMEL 89C52 Programming

Postby ssm14293 » Sat Feb 05, 2011 6:06 pm

thnx man!!
one more thing...
im writing it in normal english:
if a = 1 and P1.0 = 1 then P0.0 = 1
is this the correct way26832683

Code: Select all
if ( a == 1 & P1 == 0x80){
      P0 = 0x00;
}


and i wana say that:
if a = 1 and (b = 1 or c = 1 or d = 1) then P0.5 = 1 and P0.0 = 1
is this correct268326832683

Code: Select all
if ( a == 1 & ( b == 1, c == 1, d == 1)){
     P0 = 0x88;
}


Thankx!!
// ZacK ValentinE \\
ssm14293
 
Posts: 10
Joined: Thu Feb 03, 2011 8:13 pm

Re: ATMEL 89C52 Programming

Postby ikalogic » Sat Feb 05, 2011 6:36 pm

ssm14293 wrote:thnx man!!
one more thing...
im writing it in normal english:
if a = 1 and P1.0 = 1 then P0.0 = 1
is this the correct way26832683

Code: Select all
if ( a == 1 & P1 == 0x80){
      P0 = 0x00;
}


and i wana say that:
if a = 1 and (b = 1 or c = 1 or d = 1) then P0.5 = 1 and P0.0 = 1
is this correct268326832683

Code: Select all
if ( a == 1 & ( b == 1, c == 1, d == 1)){
     P0 = 0x88;
}


Thankx!!


the 'OR' parameter is set by the '||' symbol
In c, the '&' symbol means the "AND" operation, bit by bit. '&&' is used to say that both conditions have to be met. While this will work most of the time, i would stick to the canonical way of doing it:
Code: Select all
if ( (a == 1) && (P1 == 0x80)){
      P0 = 0x00;
}

if ((a == 1) && ( ( b == 1) || (c == 1)||(d == 1) )){
     P0 = 0x88;
}
True wisdom is knowing what you don't know -- Confucius
User avatar
ikalogic
Site Admin
 
Posts: 2236
Joined: Wed Jan 02, 2008 2:00 pm
Location: Limoges, France

Re: ATMEL 89C52 Programming

Postby ssm14293 » Sat Feb 05, 2011 7:06 pm

Thank you very much bro!!
i cant show my gratitude!!!!
:D :D :D
// ZacK ValentinE \\
ssm14293
 
Posts: 10
Joined: Thu Feb 03, 2011 8:13 pm

Re: ATMEL 89C52 Programming

Postby ssm14293 » Sun Feb 06, 2011 3:02 pm

one more thing, if i wanna take an inputs at perfect delays of lets say 500ms by an IR.Receiver at P1.0 what shud the code be26832683
same goes for output, is this the correct way for output26832683
Code: Select all

if (P3 == 0x01 ){                               //if P3.0 = 1 then proceed
       delay_ms ( 200 );                      //delays 0.2 sec
       if ( P3 = 0x01 ){                        //if P3.0 = 0 then proceed (LITES TURN ON)
          b = 1                                                  //stores 1 to var b
          P0 = 0x20;                                             //P0.5 (IR.E for LITE) = 1
          delay_ms ( 800 );                                      //delays 0.8 sec
          P0 = 0x00;                                             //P0.5  = 0
          delay_ms ( 500 )                                       //delays 0.5 sec
          P0 = 0x20;                                             //P0.5 = 1
          delay_ms ( 800 );                                      //delays 0.8 sec
          P0 = 0x00;                                             //P0.5 = 0
       }else {                                        //else ( P3.1 = 0 ) after delay then proceeds
                                                                                                 (FAN TURNS ON)
          c = 1                                                  //stores 1 to var c
          P0 = 0x20;                                             //P0.5 = 1
          delay_ms ( 500 );                                      //delays 0.5 sec
          P0 = 0x00;                                             //P0.5 = 0
          delay_ms ( 500 )                                       //Delays 0.5 sec
          P0 = 0x20;                                             //P0.5 = 1
          delay_ms ( 500 );                                      //delays 0.5 sec
          P0 = 0x00;                                             //P0.5 = 0
       }

// ZacK ValentinE \\
ssm14293
 
Posts: 10
Joined: Thu Feb 03, 2011 8:13 pm

Re: ATMEL 89C52 Programming

Postby ikalogic » Sun Feb 06, 2011 3:08 pm

ssm14293 wrote:one more thing, if i wanna take an inputs at perfect delays of lets say 500ms by an IR.Receiver at P1.0 what shud the code be26832683
same goes for output, is this the correct way for output26832683
Code: Select all

if (P3 == 0x01 ){                               //if P3.0 = 1 then proceed
       delay_ms ( 200 );                      //delays 0.2 sec
       if ( P3 = 0x01 ){                        //if P3.0 = 0 then proceed (LITES TURN ON)
          b = 1                                                  //stores 1 to var b
          P0 = 0x20;                                             //P0.5 (IR.E for LITE) = 1
          delay_ms ( 800 );                                      //delays 0.8 sec
          P0 = 0x00;                                             //P0.5  = 0
          delay_ms ( 500 )                                       //delays 0.5 sec
          P0 = 0x20;                                             //P0.5 = 1
          delay_ms ( 800 );                                      //delays 0.8 sec
          P0 = 0x00;                                             //P0.5 = 0
       }else {                                        //else ( P3.1 = 0 ) after delay then proceeds
                                                                                                 (FAN TURNS ON)
          c = 1                                                  //stores 1 to var c
          P0 = 0x20;                                             //P0.5 = 1
          delay_ms ( 500 );                                      //delays 0.5 sec
          P0 = 0x00;                                             //P0.5 = 0
          delay_ms ( 500 )                                       //Delays 0.5 sec
          P0 = 0x20;                                             //P0.5 = 1
          delay_ms ( 500 );                                      //delays 0.5 sec
          P0 = 0x00;                                             //P0.5 = 0
       }



Yes, that seems like one simple way to do it, but take care there is a mistake here:
if ( P3 = 0x01 ){
it should be :
if ( P3 == 0x01 ){
True wisdom is knowing what you don't know -- Confucius
User avatar
ikalogic
Site Admin
 
Posts: 2236
Joined: Wed Jan 02, 2008 2:00 pm
Location: Limoges, France

Re: ATMEL 89C52 Programming

Postby ssm14293 » Sun Feb 06, 2011 3:20 pm

WOW.....that works.....sorry type error...thnx for noting it!! :P :D
// ZacK ValentinE \\
ssm14293
 
Posts: 10
Joined: Thu Feb 03, 2011 8:13 pm

Re: ATMEL 89C52 Programming

Postby ssm14293 » Fri Feb 11, 2011 7:48 am

i bro...im using touch buttons is this code correct to save time interval to var a...each press will overwrite the previous value, will variable work with { delay_ms() } :

Code: Select all
void main() {
unsigned short a, b, c ;                                       //declares variable a - c

//HID SENSITIVITY CONTROL

if (P3 == 0x01){                                               //if P3.0 = 1 then proceeds
   a = 20;                                                     //Sets the time b/w intervals to 0.020 sec
   }
if (P3 == 0x02){                                               //if P3.1 = 1 then proceeds
   a = 25;                                                     //Sets the time b/w intervals to 0.025 sec
   }
if (P3 == 0x04){                                               //if P3.2 = 1 then proceeds
   a = 30;                                                     ////Sets the time b/w intervals to 0.030 sec
   }
}
// ZacK ValentinE \\
ssm14293
 
Posts: 10
Joined: Thu Feb 03, 2011 8:13 pm

Re: ATMEL 89C52 Programming

Postby ssm14293 » Fri Feb 11, 2011 9:52 am

one more thing bro...i want to loop this command until P1.0 = 0
how should i do dat26832683

Code: Select all

P0 = 0x01;
delay_ms ( 10 );
P0 = 0x00;
delay_ms ( 10 );

// ZacK ValentinE \\
ssm14293
 
Posts: 10
Joined: Thu Feb 03, 2011 8:13 pm

Re: ATMEL 89C52 Programming

Postby ikalogic » Sat Feb 12, 2011 7:50 pm

ssm14293 wrote:one more thing bro...i want to loop this command until P1.0 = 0
how should i do dat26832683

Code: Select all

P0 = 0x01;
delay_ms ( 10 );
P0 = 0x00;
delay_ms ( 10 );



just encapsulate your code with
Code: Select all
while(P1.0 == 1){
..
..your code to loop..
..
}
True wisdom is knowing what you don't know -- Confucius
User avatar
ikalogic
Site Admin
 
Posts: 2236
Joined: Wed Jan 02, 2008 2:00 pm
Location: Limoges, France

Re: ATMEL 89C52 Programming

Postby ssm14293 » Mon Feb 14, 2011 4:58 pm

hey bro thanx alot!!
can u please tell me how make a programmer...i m having a hard time finding it...
im using 89C52....please tell me the programmer!!
// ZacK ValentinE \\
ssm14293
 
Posts: 10
Joined: Thu Feb 03, 2011 8:13 pm

Re: ATMEL 89C52 Programming

Postby ssm14293 » Fri Dec 16, 2011 1:37 pm

hello,
its me again... :D
I am confused about how to make a Port input and output in MikroC for 8051 for 89C52. and also how to give outputs on a certain pin.
i have used PICs before but im newbie at this.

Thanks in advance.

PS: Compiler: MikroC for 8051
Micro controller: 89C52
// ZacK ValentinE \\
ssm14293
 
Posts: 10
Joined: Thu Feb 03, 2011 8:13 pm


Return to Micro controllers

Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 1 guest

cron