What value is written onto microcontroller pins if i send the value as character type in Embedded c program

8051c

#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

Best Answer

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'.