CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

RS232 Simulation with Mplab 7.0

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








RS232 Simulation with Mplab 7.0
PostPosted: Mon Jun 27, 2005 3:05 am     Reply with quote

Hello,
i try to simulate a 16f628 HW Uart in MPlab V7.00, but i will get only the following error:

->UART-W0003: Attempt to transmit data when Port pin direction for UART is set to an input (1).

this is in MPlab Sim Output window, no data is shown in the Sim1 Uart window from Mplab.

Is is possible to Simulate the Standard (HW Uart) in MPlab Sim ?

In my CCS compiler is initialized the RS 232 Port with:

#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=9)

so it should use the on device hardware uart, or not ?

when i do a printf, or puts function i will only get the error above.


Please can someone help me,


Greetings
Markus
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 27, 2005 11:33 am     Reply with quote

Quote:
Is is possible to Simulate the Standard (HW Uart) in MPlab Sim ?

Yes, it works.

I assume that you want to use the "UART1" feature of MPLAB
to display RS232 output in the MPLAB Output window.
But first, I suggest that you upgrade to MPLAB 7.10 or greater.
I recall that earlier versions of MPLAB had problems with UART1 output.

Here's how to do it:

1. Create a test project with the following program.

Code:
#include <16F628.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1, ERRORS)

//========================
void main()
{

printf("Hello World\n\r");

while(1);
}


2. In the MPLAB Debugger menu, go to "Select Tool" and then choose
"MPLAB SIM".

3. Again in the Debugger menu, go to Settings (at the bottom).
In the Settings window, click on the "UART1 IO" tab.

4. Then select the box for "Enable UART1 IO", and also select the box
for Output to a Window. (The Rewind File setting doesn't matter
because we're not using an input file). Then click OK.

5. Now you're back in the main MPLAB screen. Click the Compile
button to compile the file.

6. Then click the Run button. In the Output Window, there should be
a tab called "SIM Uart1". It should display this:
Quote:
Hello World


7. Then click the Halt button to stop the program.

Edited to Add:
Sometimes the UART1 still acts flakey even with MPLAB 7.10.
If you change the PIC in the #include statement and re-compile
and run it, then MPLAB will display a UART1 error message.
To fix this, you have to go into the UART1 IO window and just
click the "OK" button again. (The settings are unchanged).
Then re-compile and run the program. It will now work OK.

Note: The comments above don't apply to later versions of MPLAB.
Later versions work OK.

Edited to add the note above.


Last edited by PCM programmer on Mon Aug 04, 2014 1:50 pm; edited 2 times in total
Guest








PostPosted: Mon Jun 27, 2005 3:26 pm     Reply with quote

Hy,

so, it now works fine for me.

I have to use the Set_Tris_ Statement to say mplab that my txd pin is an output, and now it works fine.

Bye the way is it possible to read out the tris register like
x=tris(Port B) ?.

Greetings
mc_eddy
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 27, 2005 3:36 pm     Reply with quote

Quote:
By the way is it possible to read out the tris register like
x=tris(Port B) ?.

Use the #byte statement to define the address of the TRISB register.
(Look up the address in the 16F628 data sheet, in the section on Memory
organization / Special Function Registers.) Then just read the register
with a line of C code, as shown in the program below.

Code:
#include <16F628.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1, ERRORS)

#byte TRISB = 0x86
//========================
void main()
{
int8 value;

value = TRISB;

while(1);
}
albert
Guest







UART simulation error
PostPosted: Wed Jul 13, 2005 7:49 pm     Reply with quote

I'm trying to simulated your example in posted text, and there are some error shown in sim_window.

I used Mplab 7.2 ,and ccs 3.15 version.

the error message is shown as below
CORE-E0002: Stack under flow error occurred from instruction at 0x000804
CORE-E0002: Stack under flow error occurred from instruction at 0x000804
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 13, 2005 8:19 pm     Reply with quote

Quote:
ccs 3.15 version.

Can you post the full version number of your CCS compiler ?
CCS uses three digits after the decimal point, not two.
It will be a number such as 3.150 or 3.226, etc.

Look at the top of the .LST file for your program. The compiler
makes a .LST file every time you successfully compile a program,
so look for it in your Project folder.
Albert
Guest







PostPosted: Tue Jul 19, 2005 2:37 am     Reply with quote

CCS PCM C Compiler, Version 3.150, 15174
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 19, 2005 12:24 pm     Reply with quote

I installed your version and tested it with MPLAB vs. 7.20.
It fails in the same way.

The problem is that your compiler version can't generate COFF files.
CCS didn't start doing that until vs. 3.157. From their versions page:
Quote:
3.157 The compiler can now generate COFF debug files


Here's how to fix it:
In MPLAB, go to the Project menu. Select Build Options, and then in
that window under the Debug options, pick "Expanded COD Format".
Then re-compile and run it. It should now work.

Make sure that you follow the instructions that I posted previously
in this thread.
albert
Guest







PostPosted: Wed Jul 20, 2005 5:17 am     Reply with quote

TKS!!

It's Work! , but what's different between with/without expanded COD format. thanks your reply !
guest
Guest







invalid baud rate
PostPosted: Mon May 01, 2006 5:25 pm     Reply with quote

Using PCM compiler I get an invalid baud rate error when using RS485.c include in example files with my RFID protoboard.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon May 01, 2006 9:47 pm     Reply with quote

Then you have probably chosen a clock frequency that will not support the baud rate because the frequency is too slow or the % error is too high.
guest
Guest







thanks it worked, but now another problem
PostPosted: Tue May 02, 2006 6:00 pm     Reply with quote

so that worked and got all our code to work even down to the leds... we have the universal problem of hyperterminal not showing our printf functions. however.. when pressing G or R we get either LED to GREEN with a delayed response of BAD or LED to RED and a delayed response of BAD. We did not code that but thats what we get in hyperterminal. Any help?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group