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.

Problem in Serial Communication using PIC

Status
Not open for further replies.

th3gr8

Member level 4
Member level 4
Joined
Aug 27, 2013
Messages
68
Helped
6
Reputation
12
Reaction score
6
Trophy points
8
Visit site
Activity points
398
Hello everybody ..
I am working with Serial Communication using Pic MCU .. I got a problem in that .. It is that the programs that consumes less RAM and ROM are working fine (i.e. their outputs are fine at HyperTerminal), but the outputs of the programs that consumes more RAM and ROM (even 20% of RAM and ROM) of MCU doesn't even appear at the HyperTerminal.. Also, when i press the data-lines again and again, i receive some garbage characters on the hyperterminal .. Is there something wrong with my hardware?? :( .. Plz help !!
I am using PIC16F877A, 4MHz crystal and PIC-CCS for programming ..
Here is the code:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// To Calculate Radius of Circle using RS232 Protocol
#include <16F877A.h>
#fuses HS, NOLVP, NOWDT,BROWNOUT
#use delay(clock = 4Mhz)
#use rs232(baud=9600, xmit=pin_B0, rcv=pin_B1)
 
void main()
{
unsigned int r=0,c;
float a=0;
lcd_init();
delay_ms(30);
loop:
printf("\n\rInsert value of r (from 0-9): ");
r = getc();
putc(r);
delay_ms(1000);
r = r-48;
lcd_putc('\f');
lcd_gotoxy(1,1);
//lcd_putc(r);
printf(lcd_putc,"Radius = %d", r);
a = (3.14*r*r);
printf("\n\rArea of circle = %f", a);
lcd_gotoxy(1,2);
printf(lcd_putc,"Area = %f", a);
printf("\n\rRepeat? (Y/N): ");
c = getc();
putc(c);
if(c=='y')
{
goto loop;
}
else
{
break;
}
}

 
Last edited by a moderator:

Try to code without using the 'goto' instruction - you will regret it later when your programs are more advanced. Also consider where the 'break' leads to in line 36.

I think your underlaying problem is that you use 'printf' and also floating point math, both are huge memory hogs and relatively slow on PICs without multiplication support. 18F devices are better, faster and have more memory for this kind of application.

If you want to make it smaller, try this:
1. make the fixed text into a const array. For example "const char *Text1 = {"Radius = "}; // this puts the text in ROM instead of RAM
2. send the characters one at a time from the array in a loop.
3. instead of using 3.14, use 314 and shift the decimal two places in the result. This lets integer math instead of floating point be used.

Brian.
 
  • Like
Reactions: th3gr8

    th3gr8

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top