0
\$\begingroup\$
#include<reg51.h>
     sbit sw=P1^0;
     sbit led=P1^1;
    void write(unsigned char m);
     void delay(unsigned char k);

     void main(){
      while(1){ 
        delay(60);    
         sw=1;
         led=0;
         if(sw==1){
           delay(50);
           write(1);}
          else{
           delay(50);
           write(0);} 
           }}

           void write(unsigned char m){
              led=m;}

           void delay(unsigned char i)
           { unsigned int k,l;
           for(l=0;l<=i;l++)
           for(k=0;k<65500;k++);
           }

what value is received by write function whether it is character or integer? i want to send integer value to write on led? is it right?plz tell me

\$\endgroup\$
  • \$\begingroup\$ How is led defined? \$\endgroup\$ – Wouter van Ooijen Feb 20 '15 at 14:28
  • \$\begingroup\$ why dont you use int instead of char. It is possible you will get correct output. \$\endgroup\$ – sharan choudhary Feb 20 '15 at 14:31
  • \$\begingroup\$ led is defined as output pin \$\endgroup\$ – chakravarthi merugumalli Feb 20 '15 at 14:31
  • \$\begingroup\$ i want to use character for decreasing memory size as character requires 1 byte and interger requires 2 bytes \$\endgroup\$ – chakravarthi merugumalli Feb 20 '15 at 14:35
  • \$\begingroup\$ That is not a C primitive, so it leads to the next question: how is a pin defined? \$\endgroup\$ – Wouter van Ooijen Feb 20 '15 at 14:38
4
\$\begingroup\$

char and unsigned char are numeric types; whatever value you assign to a variable of type char or unsigned char is the value that the variable will hold. So the 0 and 1 values in the two calls are fine.

Yes, C also uses char to represent character values, but that's a convenience: it doesn't affect what values are held. If you assign 1 to a char variable, the variable holds the value 1. If you assign 'a' to a char variable, the variable holds whatever value the 'a' represents; these days it will be 97, which is the ASCII representation for 'a'.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.