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

PIC16F88 UART

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



Joined: 09 Oct 2009
Posts: 13
Location: SF,BG

View user's profile Send private message

PIC16F88 UART
PostPosted: Fri Dec 25, 2009 3:53 am     Reply with quote

Hi,
I have a problem with configuration of UART on pic16f88. This is my code:
Code:

#include <16F88.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES XT                       //Resistor/Capacitor Osc with CLKOUT
#FUSES NOPUT                    //No Power Up Timer
#FUSES MCLR                     //Master Clear pin enabled
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES LVP                      //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOPROTECT                //Code not protected from reading
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES IESO                     //Internal External Switch Over mode enabled

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8)

#include "C:\Users\ILS\Desktop\GSM Dialer\main.h"

void main()
{
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   for(;;)
   {
       printf("ATD+359XXXXX");
       delay_ms(20000);
   
   }
 }

I have simulated code in proteus and it works. I make the PCB and it
does not work. I measured with oscilloscope and there wasn't a signal on
the output(PIN 11). Where is my mistake?
Thank's
Ttelmah
Guest







PostPosted: Fri Dec 25, 2009 5:40 am     Reply with quote

Probably the oscillator is not running.
XT=4MHz max.....

Best Wishes
peterl+
Guest







pic16f88 UART
PostPosted: Fri Dec 25, 2009 7:25 am     Reply with quote

I measured PIN15/16 with oscilloscope and I saw that oscillator work. Confused
Ttelmah
Guest







PostPosted: Fri Dec 25, 2009 10:37 am     Reply with quote

Correct it anyway. The 'odds' are that it will be running at a lower frequency 'undertone', rather than at the 20MHz harmonic that it should be on.

What compiler version?.

A search here will find previous threads, where some versions don't initialise the UART properly. However this should be visible in the simulation. Unfortunately, Proteus, is not as accurate at spotting such things as MPLAB, so might well work, with it setup incorrectly....

Best Wishes
peterl+
Guest







PIC16F88 UART
PostPosted: Fri Dec 25, 2009 12:05 pm     Reply with quote

Ok, I will make it 4 MHZ. Compiler version is 4.084.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 25, 2009 12:23 pm     Reply with quote

Quote:
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

Get rid of all this Wizard code. You don't need any of it, and in fact,
the line in bold is setting the TRIS on pin B2 to be an output pin,
which is the opposite of what you need for the UART Rx pin.
Delete all those lines above.

Quote:

#FUSES LVP

This is wrong. If pin B3 goes high, the PIC will lock up. Change it to
NOLVP. Proteus probably ignores this feature, but in a real hardware
design, you will see the problem.


Quote:
I measured PIN15/16 with oscilloscope and I saw that oscillator work

It doesn't matter if it "works". The vast majority of the time, it will not
work when you use XT with a 20 MHz crystal. Always use HS with 20 MHz.
Also, make sure you have the correct capacitors in the crystal circuit.
A commonly used value is 22 pf.
asmboy



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

View user's profile Send private message AIM Address

PostPosted: Fri Dec 25, 2009 12:51 pm     Reply with quote

not to pile on here BUT:

you were using NOPUT - with a crystal - not an X-O

i don't thinks that i so swift w/ HS xtals !!

try fuse: PUT instead !!

i have a design that uses 18.432Mhz for precise baud division -

with older 16Cxxx PICs in particular
- i have found that above 12MHZ - generally I get best startup ( observed on CLKOUT with SCOPE ) on many different designs with pashing caps as low as 15 -18pf & YES HS setting ONLY

i typically use 18Pf with 16F series
just a few PF can make a difference in how quickly the oscillator starts and settles



just my 2 cents
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 25, 2009 1:10 pm     Reply with quote

If you want to stock only one value, 22 pf works reliably with both 4 MHz
and 22 pf crystals. In some cases it might pull the crystal off frequency
very slightly, but in most applications that doesn't matter.
peterl+
Guest







PIC16F88 UART
PostPosted: Sat Dec 26, 2009 7:33 am     Reply with quote

Hi guys,
this is my repaired code:
Code:
#include <16F88.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //Resistor/Capacitor Osc with CLKOUT
#FUSES NOPUT                    //No Power Up Timer
#FUSES MCLR                     //Master Clear pin enabled
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES NOLVP                      //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOPROTECT                //Code not protected from reading
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES IESO                     //Internal External Switch Over mode enabled

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8)



#include "C:\Users\ILS\Desktop\GSM Dialer\main.h"


void main()
{
   for(;;)
   {
       printf("ATD+359XXXX");
       delay_ms(1000);
   
   }
 }

But it's still not working :( I tried with #FUSES NOPUT and with #FUSES PUT but changes has no effect. I didn't replace crystal, because magazines not working today. The capacitors is 20pf. Now I will connect my dialer with RS232-TTL converter to see UART sending something,
Best regards.
peterl+
Guest







PIC16F88
PostPosted: Sat Dec 26, 2009 7:51 am     Reply with quote

The PIC works, I saw my AT command on hyperterminal Smile , but the problem actually is that the GSM not dial.
Ttelmah
Guest







PostPosted: Sat Dec 26, 2009 2:59 pm     Reply with quote

You need to put the modem into 'command mode'.
You have to remember that it'll quite probably have seen some garbage as the PIC wakes up, so will probably have switched to data mode.
The default for a modem is to wake up in command mode, but if you see _anything_ that is not a legitimate command it switches to data mode. Switching to command mode is triggered by sending:

Line Feed
Pause 1 second
+++
Pause 1 second

Try sending this at the start of your code, then the AT command
Remember also,once you have sent the AT command you should look for, and wait for the 'OK' reply. Only retry the AT command, if this is not seen.

Best Wishes
peterl+
Guest







16F88 UART
PostPosted: Thu Dec 31, 2009 8:13 am     Reply with quote

Sorry for stupid question, but what mean "Line Feed"?
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu Dec 31, 2009 8:39 am     Reply with quote

It means an ASCII LF character.

The ASCII Chart here:
http://www.asciitable.com/
_________________
Google and Forum Search are some of your best tools!!!!
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