Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

mikro c to mplab conversion for car alarm system

Status
Not open for further replies.

lifiq

Junior Member level 2
Junior Member level 2
Joined
Jan 11, 2011
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,497
i have a code here in mikro c but can anyone pls help me to convert it into c code so that it can be compiled and be used in the mplab software......im doing a project on a car alarm system using pic16f877a mcu....pls guys

#define intruder PORTB.f7
#define button_ON PORTB.f6
#define blockcar PORTD.f7


char j[10] = "AT+CMSS=1"; // COMMAND SEND MESSAGE FROM STORAGE TO PHONE
int enter = 0X0D; // COMMAND FOR ENTER
char i;




void main()
{

trisb = 0xff; // SET PORTB AS INPUT
portd = 0x00; // SET INITIAL VALUE FOR PORTD
trisd = 0x00; // SET PORTD AS OUTPUT
UART1_Init(9600); // SYNCHRONIZE BAUDRATE WITH HANDPHONE
trisc.f7 = 1; // SET Rx DATA IN
trisc.f6 = 0; // SET Tx DATA OUT

while(1)
{
ON:
while(1)
{
blockcar=0; // SET INITIAL FOR NOT BLOCKING CAR
if(button_ON==1) // ON OR NOT THE SYSTEM
{
if(button_ON==0)
{
goto ON;
}
else if
(intruder==0) // FIND OUT IF THE DOOR STILL OPEN OR NOT
{
goto INTRUDER; // GO TO CHECK FOR AN INTRUDER
}
}
}

INTRUDER:
while(1)
{
if(button_ON==0)
{
goto ON;
}
else if((intruder==1)&&(button_ON==1)) // CHECK IF THERE IS AN

{
goto SSMS; // GO TO SENDS SMS AFTER

}
}
SSMS:
while(1)
{
for(i=0;i<10;i++)
UART1_Write(j); // SENDING CHARACTER FOR SENDS SMS

UART1_Write(enter);
goto USERINT; // GO TO BLOCKING CAR
}
USERINT:
while (1)
{
blockcar=1; // BLOCKING THE CAR
if (button_ON==0) // WAIT FOR USER INTERRUPT
{
goto ON; // BACK TO START AFTER USER INTERRUPT
}
}
}
}
 

If I could offer a critique of your code: it might be simpler and more readable to implement this as a software state machine. All those "goto"s are going to be nothing but trouble later on when you try to remember what this code does or try to find out why it's not working.

To work with the Hi-Tech PIC compiler, I think you'll need to change the "trisc.f6" statements to something like TRISCbits.TRISC6. The port names also need to be in capitals.
 
i did it using proteus and it works fine but when implementing this using breadboard the RB6 for turning it on directly initiates RD7 which is output to turn on...what should i do...can u modify the code for the better....thanks alot dude
 

Dude, I think you might have a switch bounce problem. Are you debouncing the input switches in hardware or software? Real switches have contact bounce -- unlike simulated ones ;-)
 

so what shall i do....im doing it in hardware and im facing this problem.....in software it works perfectly fine.....when i do it in hardware the on button directly triggers the output in pin rb7.
 

Perhaps your hardware debouncing is not working? What circuit are you using? Typically you need a debounce filter of around 50 to 100mS. If possible, check that a clean switch output is present at the processor input.

Another possibility may be that your code has a race condition where it doesn't wait for a switch edge and instead is triggered by the switch level. That could be getting you into trouble.

If you know what a state machine is you really should look at implementing your logic as one. I can see basically four states. Once you implement the state machine, it will be obvious what's happening -- assuming the problem is in the software.
 

i have tested with other programs for led blinking and stuff and it has no problem......one thing new that i find out is that when i hold a any component in the circuit such as resistor capacitor or crystal it works fine no issues....but when i leave it untouched the output pin will start blinking the led.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top