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.

[SOLVED] Mikroc working not properly

Status
Not open for further replies.

Johnny Churne

Member level 5
Joined
Jun 5, 2015
Messages
83
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
554
I have download Mikroc to my computer. I write Uart program it won't work in real hardware test. But when I download the Uart hex file from the internet it work but not properly too.
I am unable to receive data from pic 16f877A.
Please any one help very much Thank you.
 

You are asking us to diagnose a problem in a program we have not seen.

What is the program code?
What doesn't work?
What have you tried already?

Brian.
 

I am unable to receive correct address from pc if I send number 1 pic receive letter a. Another thing when I send data back to pc, pc unable to receive any thing. I would ask you why like this.
My program


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
Char ch;
Void main(){
uart1_init(9600);
While(1){
If(uart1_data_ready()){
ch=uart1_read();
Uart1_write(ch);
}
}
}

 
Last edited by a moderator:

The symptoms suggest that either the speed or stop bits are set wrongly. I assume the PC is set to use 9600 bauds, no parity and 1 stop bit.
The line "uart1_init(9600)" calculates the divisor needed to create the baud rate by dividing the PIC clock speed by a multiple of 9600 so check you have correctly specified what the clock speed is in your program.

I hope you are using an interface between the PICs low voltage (VSS to VDD) UART pins and the PCs RS232 levels!

Brian.
 

Use 9615 for the baudrate. There is a 0.16% error in baudrate if you use 9600. You should also have a while(1) loop and inside it you should have your UART receive and send codes. You have also not mentioned which PIC and what clock frequency you are using. As you are trying to receive UART data sent from PC you have to set the TRISx of Rx pin as input type. If there is ADC function on UART lines then you have to disable them and make the UART pins as digital IO pins.
 

Use 9615 for the baudrate. There is a 0.16% error in baudrate if you use 9600.
Somebody isn't doing the math! Set it to 9600!

The error depends entirely on the clock speed, if you set it to anything other than 9600 you risk it being even further away from accurate.

You should also have a while(1) loop and inside it you should have your UART receive and send codes
My eyesight must be failing.

Brian.
 

My eyesight must be failing.

Sorry, I didn't see the
Code:
while(1)
loop.

Here I am attaching a mikroC PRO PIC UART project. I have used 4 MHz crystal. I have posted this as OP is also using mikroC PRO PIC Compiler. See attached image. In mikroC if 9600 is used then it still generates 9615 bps and it works but it gives a warning message as shown. To eliminate the message in compiler one can pass 9615 for the
Code:
UART1_Init()
function.

Whatever value is used for baudrate mikroC doesn't generate exact 9600 bps.

broken link removed
 

Attachments

  • uart.png
    uart.png
    117.8 KB · Views: 230
  • UART.rar
    132.4 KB · Views: 73
Last edited by a moderator:
  • Like
Reactions: bin95

    bin95

    Points: 2
    Helpful Answer Positive Rating
Seting the wrong value is dangerous and should not be done. Indeed, with a 4MHz crystal the nearest actual baud rate is 9615 but that assumes a PIC with an 8-bit baud rate generator and that 4MHz is being used. 'Adjusting' the expected result to avoid a compiler warning can lead to other problems and loss of code portability.

In most cases, a baud rate error of up to about 2% can be tolerated so 0.15% is insignificant.

Brian.
 

I use pic 16f877a max 232n, capacitor 10uf sub to com baunrate 9600
Crystal 8 MHz.

- - - Updated - - -

I use pic 16f877a, max232n capacitor10uf, crystal 8 MHz, usb to com.
Thanks for your care I really appreciate for your help. Love to see your reply.
 

It should work. Can you post the complete schematic, I suspect something is wrong electrically rather than in software.

Brian.
 

Here is my circuit diagram I am following Mikroc procedure. I used 2capacitors 33pf with 8 MHz crystal. I could not use L7805n because when I use it pic unable to give voltage to led even though I give 12v
I connected it directly to 5v and 500mA iPad adaptor.
 

Attachments

  • image.jpg
    image.jpg
    240.2 KB · Views: 90
  • image.jpg
    image.jpg
    1.6 MB · Views: 102

I can see some possible causes of your problem. Please try:

1. Add 100nF capacitors between the VSS and VDD pins at both sides of the PIC. Wire them between the pins rather than the outside strips of the board as the wiring length is important and should be a short as possible. Reason: The PIC and MAX232 draw current in short pulses and the supply wiring resistance and inductance is probably causing the voltage between VSS and VDD to fluctuate. The capacitors will help to keep the voltage constant.

2. Do the same across pins 15 and 16 of the MAX232 to help stopping it radiating interference into the supply.

3. The MikroC schematic shows the clock being generated from an external source and fed into pin CLKIN, you are using a crystal instead. There is no problem doing that but ensure you have the configuration set to use the internal oscillator in HS mode or it will not run or it may run at the wrong frequency.

4. This is important: you MUST add resistors in series with the LEDS or you risk damaging the PIC and possibly the LEDs as well. Without the resistor they will try to draw far too much current and the LED and PIC pin drivers will be overloaded, this may be the reason the LM7805 did not work. I suggest you add a resistor of 470 Ohms in series with each of the LEDS.

Try these ideas and let me know how you get on.

Brian.
 

Here is my circuit diagram I am following Mikroc procedure. I used 2capacitors 33pf with 8 MHz crystal. I could not use L7805n because when I use it pic unable to give voltage to led even though I give 12v
I connected it directly to 5v and 500mA iPad adaptor.
 

I did what you told me add 100uf in both vss and vdd and pin 15 16 of Max 232. I wire shortly Rx and Tx. But it still the same. When I send number 1 pic receive letter a and it won't send back to Mikroc.
 

This is my program in Mikroc.
 

Attachments

  • image.jpg
    image.jpg
    1.9 MB · Views: 107

Divide and conquer - split the probem in two halves. Change the line 'uart1_write(ch);' to 'uart1_write('X');' and see if it responds with an 'X' for each character you send it.

Brian.
 

I configur RC6 as out put and uart1_write('X')
It is the same! Do you think maybe the compiler? Please send your hex file Let me try.
Before, I download Mikroc from it web, I compile it work in proteus but when I install to pic it not work. I found Mikroc in pirate bay web then I download and ***** it now in work only this thing.
 

Attachments

  • image.jpg
    image.jpg
    1.8 MB · Views: 97

Whether you copy of MikroC is working is debatable in view of it's origin.

However, if it simulates OK but the real hardware doesn't work, it suggests an electrical or chip programming problem is the cause. Did you try the suggestions in post #12?

Brian.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top