コード例 #1
0
ファイル: keypad_dcmotor.c プロジェクト: RajViky/PIC-Projects
void main()
{
kp=0;
t=0;
keypad_init(&portd);
trisd=0x00;
trisb=0x00;
portb=0x00;
portd=0x00;
kp=keypad_read();
while(1)
{
kp=keypad_read();
switch(kp)
{
case 1:do
       {
       portb.f2=1;//ENABLE
       portb.f1=1;
       portb.f0=0;
       t=keypad_released();
       }while(t=0);
       t=0;
       break;
       

case 2:do
       {
       portb.f2=1;//ENABLE
       portb.f1=0;
       portb.f0=1;
       t=keypad_released();
       }while(t=0);
       t=0;
       break;


case 0:do
       {
       portb.f2=0;//ENABLE
       portb.f1=0;
       portb.f0=0;
       t=keypad_released();
       }while(t=0);
       t=0;
       break;

}
}
}
コード例 #2
0
/*******************************************************************************
* MAIN FUNCTION                                                                *
*******************************************************************************/
int main(void)
{
	unsigned char ucStatus;
	unsigned char ucData;
	unsigned char key_send;
        unsigned char key;
	
        initialzie();

	while (1)
        {
		// If data is received...
		if (IRQ == 0)
                {
			ucStatus = ucNrf24l01ReceivePacket(&ucData, 1);

			// Make sure data is read out successfully.
			if (ucStatus != 0)
                        {
                                LCD_goto(0, 0);
                                LCD_putstr("Receive ");
                                LCD_goto(1, 0);
				LCD_putchar(ucData);
				// Turn on/off LED1 according to the data received.
				if (ucData == '1')
                                {
					LED1 = 1;
				}
				else if (ucData == '2')
                                {
					LED1 = 0;
				}
                        }
                }

            while((key = keypad_read()) != 0xFF)
            {
 			// Enable Tx mode.
                        key_send = keypad_wait(); //ASCII_value(keypad_wait());
                        LED1 = ~LED1;
                        __delay_ms(30);
                          LCD_goto(0, 0);
                          LCD_putstr("Transmit");
                          LCD_goto(1,0);
                        LCD_putstr("Mode");
                        __delay_ms(40);
			vNrf24l01EnableTx();

			ucStatus = ucNrf24l01TransmitPacket(&key_send, 1);

			// Change back to Rx mode.
                        vNrf24l01EnableRx();
            }
        }
}