Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void LeftMotor(int,int,int);
- void RightMotor(int,int,int);
- void NumaleeSong(void);
- unsigned char ir_cmd=0;
- //------------------ Interrupt service routine INT -----------------//
- void interrupt(){
- unsigned char i; // Keep counter
- if(INTCON.INTF) // Check interrupt flag RB0 (Falling edge)
- {
- Delay_us(416); // Delay 1/2 of 1 bit timing
- // (baudrate 1200 bps)
- for(i=0;i<8;i++) // Loop 8 times for keep data from ER-4
- {
- Delay_us(833); // Delay of 1 bit timing
- // (baudrate 1200 bps)
- ir_cmd = ir_cmd>>1; // Shitt bit 1 time
- if((PORTB & 0x01)==1) // Get logic @ RB0 = '1'?
- ir_cmd = ir_cmd | 0x80; // Inset bit data is '1'
- }
- Delay_us(833); // Delay of 1 bit timing
- // (baudrate 1200 bps)
- INTCON.INTF =0; // Clear interrupt flag
- }
- }
- //------------------ Function for get character from Remote ---------//
- unsigned char get_remote()
- {
- unsigned char _key=ir_cmd; // Get character to buffer
- ir_cmd=0; // Clear old data
- return(_key);
- // Return character from Remote
- }
- void main()
- {
- unsigned char key; // Save Remote Key Press
- ANSELH.F4 = 0;
- ///////////////Left Motor Connection/////////
- TRISD.F0 = 0;
- TRISD.F1 = 0;
- TRISC.F2 = 0;
- ///////////End Left Motor Connection/////////
- ANSELH = 0x00; //Set Port B Logic Status
- ///////////////Right Motor Connection///////
- TRISB.F1 = 0;
- TRISB.F2 = 0;
- TRISC.F1 = 0;
- ///////////End Right Motor Connection/////////
- Lcd_Init(&PORTD); //LCD Connection
- TRISB.F3 = 0; //LED Connection
- Sound_Init(&PORTc,0); //Speaker Connection
- while(1)
- {
- Lcd_Cmd(LCD_CLEAR);
- key = get_remote();
- if(key=='a' || key=='A') //if press A then backward
- {
- Lcd_Out(1,4,"Backward");
- LeftMotor(0,1,1);
- RightMotor(0,1,1);
- Sound_Play(2000,500);
- Delay_ms(100);
- Sound_Play(2000,500);
- }
- else if(key=='b' || key=='B') //if press B then turn right
- {
- Lcd_Out(1,3,"Turn Right");
- LeftMotor(1,0,1);
- RightMotor(1,1,1);
- }
- else if(key=='c' || key=='C') //if press C then turn left
- {
- Lcd_Out(1,4,"Turn Left");
- LeftMotor(1,1,1);
- RightMotor(1,0,1);
- }
- else if(key=='d' || key=='D') //if press D then go straight
- {
- Lcd_Out(1,3,"Go Straight");
- LeftMotor(1,0,1);
- RightMotor(1,0,1);
- }
- else
- {
- Lcd_Out(1,3,"Stop !!!"); //if don't press any button then stop all motor
- LeftMotor(1,1,1);
- RightMotor(1,1,1);
- }
- }
- }
- void LeftMotor(int x,int y,int z){
- PORTD.F0 = x;
- PORTD.F1 = y;
- PORTC.F2 = z;
- }
- void RightMotor(int x,int y,int z){
- PORTB.F1 = x;
- PORTB.F2 = y;
- PORTC.F1 = z;
- }
- void NumaleeSong(){
- Sound_Play(1975.5,250);
- Sound_Play(1760,250);
- Sound_Play(1568,250);
- Sound_Play(1760,250);
- Sound_Play(1975.5,250);
- Sound_Play(1975.5,250);
- Sound_Play(1975.5,250);
- Delay_ms(250);
- Sound_Play(1760.0,250);
- Sound_Play(1760.0,250);
- Sound_Play(1760.0,250);
- Delay_ms(250);
- Sound_Play(1975.5,250);
- Sound_Play(2349.3,250);
- Sound_Play(2349.3,250);
- Delay_ms(250);
- Sound_Play(1975.5,250);
- Sound_Play(1760,250);
- Sound_Play(1568,250);
- Sound_Play(1760,250);
- Sound_Play(1975.5,250);
- Sound_Play(1975.5,250);
- Sound_Play(1975.5,250);
- Delay_ms(250);
- Sound_Play(1760,250);
- Sound_Play(1760,250);
- Sound_Play(1975.5,250);
- Sound_Play(1568.0,250);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement