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 support@ccsinfo.com

how to use serial without #use rs232

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



Joined: 04 Jun 2008
Posts: 23

View user's profile Send private message

how to use serial without #use rs232
PostPosted: Sat Sep 01, 2012 4:10 am     Reply with quote

Hello,
I'm using a PIC18f25k20 and I want that RC6 (TX HW pin) to be at initialisation an input. I connected 100kohm to VDD and a 10kohms to ground. If 10 kohms is connected to ground that means that is on "0" logic and on the program will do something - if 10kohms is not connected to ground that means that is "1" logic and the program should do something else...
1. set the direction as input <trisc6 = 1>
2. see if 10kohms is connected or not to ground
3. set the direction as output.
Code:

   TRISC = 0XC0;  // sets the RC6 as input

   if (JMP4) //JMP4 is RC6
   {
      WF_TYPE = SWITCH_WF;
   }
   else 
   {
      WF_TYPE = THERMO_WF;
   }

I found that it doesn't matter if 10kohms is connected or not to ground - the voltage is VDD -as idle of the #use232. So, it never can be seen if the 10k ohms are or not connected to the ground.

How can I set the serial after this test?

Hope that someone understand my problem.
Thank you.
Ttelmah



Joined: 11 Mar 2010
Posts: 19347

View user's profile Send private message

PostPosted: Sat Sep 01, 2012 4:20 am     Reply with quote

#USE RS232(UART1, BAUD=0, ERRORS)

Then when you want to use the RS232, use

setup_uart(9600);

or whatever the baud you want.

Setting baud=0, tells the compiler to generate the code, _but not initialise the UART, or TRIS_.

When you use 'setup_uart' with a baud rate, the UART is initialised.

setup_uart(0);

switches the UART back off.

Best Wishes
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Sep 01, 2012 4:21 am     Reply with quote

Code:
setup_uart(0)
lboghy



Joined: 04 Jun 2008
Posts: 23

View user's profile Send private message

not work
PostPosted: Sat Sep 01, 2012 4:56 am     Reply with quote

Hello!
thank you for responses.
I used:
Code:

   setup_uart(0);

   TRISC = 0XC0;  // sets the RC6 as input
   if (JMP4)
   {
      WF_TYPE = SWITCH_WF;
   }
   else 
   {
      WF_TYPE = THERMO_WF;
   }
   TRISC = 0X80;
   
   setup_uart(57600);

But is reset at every 2-3 seconds....
I put also #use 232(0,...) and the same result - is reseting every 2-3 seconds.
Have you any idea.

Thank you very much.
temtronic



Joined: 01 Jul 2010
Posts: 9164
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Sep 01, 2012 5:17 am     Reply with quote

Without seeing your whole program it sounds like you have the WatchDogTimer enabled but are not handling it correctly..

that's my guess

hth
jay
lboghy



Joined: 04 Jun 2008
Posts: 23

View user's profile Send private message

PostPosted: Sat Sep 01, 2012 6:32 am     Reply with quote

Ok, here is the code,

On .c file:

Code:
TRISC = 0XC0;  // sets the RC6 as input
 if (JMP4)
   {
      WF_TYPE = SWITCH_WF;
   }
   else 
   {
      WF_TYPE = THERMO_WF;
   }
   TRISC = 0X80;
   
   setup_uart(57600);
 
   //end procedure

   delay_ms(20);

while(1)
{
   if(WF_TYPE == THERMO_WF)
     printf("It was selectedd the thermo...");
  else
    printf("It was selectedd the switch...");
}


at header is:
Code:

#include <18F25K20.h>
#include "SFR.h"

#device adc=10                  //  10 bits ADCs results
//#device adc=8                  // 8 bits ADCs results

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT1024                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV20                   //Brownout reset at 1.8V
#FUSES PUT                      //Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                      //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOIESO                     //Internal External Switch Over mode enabled
#FUSES NOFCMEN                    //Fail-safe clock monitor enabled
#FUSES NOPBADEN                   //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NODELAYINTOSC         
#use delay(clock=4000000)

//#use rs232(baud=57600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#use rs232(UART1, baud=0)
//#USE RS232(UART1, BAUD=0, ERRORS)

In SFR.h file I defined the TRISC, TRISB...

Thank you
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Sep 03, 2012 3:51 pm     Reply with quote

Quote:

In SFR.h file I defined the TRISC, TRISB...

that is nice BUT
did you ALSO
#USE Fast_io(B)
#USE Fast_io(C)
???
Ttelmah



Joined: 11 Mar 2010
Posts: 19347

View user's profile Send private message

PostPosted: Tue Sep 04, 2012 2:07 am     Reply with quote

Further comment:
The code posted, is not complete so it can be compiled. Unless you post enough to make the code compilable, we can never tell there is not a 'hidden beastie' causing the problem. You need to just simplify down to a minimum program showing the problem, and post it.
Second comment, there is no need to define TRIS. If you want to control the TRIS registers, then use the compiler set_tris_x functions. They are already there. However for 99% of code there is no need to ever touch TRIS with the CCS compiler, and more often than not, doing so, leads to problems, rather than making things work.....

Best Wishes
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