Dear All, I've tried to read the pin of Port1 , but i failed . I should write one to it right ? , how do i read a one again ? If i tried to write the following code,it works without checking the status of the pin Port1_3=1; if(Port1_3==1) { // execute code here .. // code here executes in the simulator //without checking if the pin is //high or not } thanks in advance
You are using the '^' incorrectly!
if ( P1^3==1)
sorry am newbie :- its supposed to be sbit P1_3=P1^3; if ( P1_3==1) { // execute ... }
its supposed to be sbit P1_3=P1^3; NO, do not use Px.y in code, only in definitions. use something like sbit SBG_P1_USB_SSI = 0x96; // USB SSI a surefire way (TCON as an example): sbit SB_TCON_TF1 = 0x8F; sbit SB_TCON_TR1 = 0x8E; sbit SB_TCON_TF0 = 0x8D; sbit SB_TCON_TR0 = 0x8C; sbit SB_TCON_IE1 = 0x8B; sbit SB_TCON_IT1 = 0x8A; sbit SB_TCON_IE0 = 0x89; sbit SB_TCON_IT0 = 0x88; This avoid ALL confusion. I like to remove confusion, that keeps me more productive. I find using SB_TCON_ in the definitions very helpful (a global search on TCON gives all uses whether bit set ot SFR load) but, if you find that distasteful, the method works with any naming convention. Erik
" ... its supposed to be ... " 1st law of programming: the compiler will do what you tell it to do; it will not attempt to second-guess what you actually wanted it to do!! So, if you actually write
sbit P1_3=P1^3; if ( P1_3==1) { // execute ... }
sbit door_open = P1^3; if ( door_open ) { // execute ... }
thanks erik. I tried to use this code and it works in the simulator, could you tell me what's ur opinion about it ? : void main (void) { pin_4=1; while(1) { while (pin_4 !=1) { P2=0xFF; DELAY_LOOP_Wait(90); if ( pin_4==1) { p++; if ( p==5) { P2=0x00; } } } }