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 Set Internal Oscillator in the PIC18F4550
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
analog_world



Joined: 16 Sep 2008
Posts: 26

View user's profile Send private message

How to Set Internal Oscillator in the PIC18F4550
PostPosted: Sat Oct 18, 2008 8:07 pm     Reply with quote

I am using pic 18F4550 to write data received from the GPS onto the LCD. I am stuck with a couple of questions.
1) I plan on using the internal oscillator of the PIC. I am using the PIC wizard considering my lack of expertise. However, I ran into a problem while trying to configure to use the internal oscillator on the options. Since the internal clock of the 18 series can be configured by software, I want to use a 8MHz clock for now. How can I DO this easily? please help. I am posting the code generated from the pic wizard.
Code:

#include <18F4550.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTHS                    //Internal Oscillator, HS used by USB
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES LVP                      //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES PBADEN                   //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 MCLR                     //Master Clear pin enabled
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL1                     //No PLL PreScaler

#use delay(clock=8000000)
#use rs232(baud=4800,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)


2)Also, I am not able to use the lcd_putc() functions to display any characters despite setting the RW, E, RS pins correctly according to my board. What is the way to fix this?

I really appreciate any help or suggestions with this. Thank you.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 18, 2008 8:50 pm     Reply with quote

Quote:
I want to use a 8MHz clock for now. How can I do this

This thread has a simple test program that runs the 18F4550 at 8 MHz
from the internal oscillator and blinks an LED:
http://www.ccsinfo.com/forum/viewtopic.php?t=28833


Quote:
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)

Are you using a low voltage programmer ? Almost all (99%) programmers
are High Voltage programmers. You are probably using that type.
If so, change the fuse to NOLVP. Do that in all your programs.


Quote:

I am not able to use the lcd_putc() functions to display any characters
despite setting the RW, E, RS pins correctly according to my board. What is the way to fix this?

What LCD driver are you using ? I suggest using the "Flex" lcd driver
in the CCS code library. Choose your pins for DB4-DB7, R/W, RS, and E.
Edit the #define statements at the top of the Flex driver file to use those
pins. Make sure the contrast pin on the LCD is set to about 0.4v initially.
It should work.
analog_world



Joined: 16 Sep 2008
Posts: 26

View user's profile Send private message

PostPosted: Sat Oct 18, 2008 10:48 pm     Reply with quote

Hi PCM,
I really appreciate your timely help in answering my questions. I had a quick question for you thought. On my board, the manual tells me that the data pins DB0-DB7 are connected to the LCD data pins and port A is the control bit (RS,RW,E). I was wondering since you are using only 4 data pins in your driver. Thanks again.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 18, 2008 11:11 pm     Reply with quote

The Flex driver uses the upper four address lines (DB4-DB7). The lower
four lines are not used. The PIC pins for those lines should be configured
as input pins. This is the power-on reset state for PIC pins, so you
don't have to do anything (in code) with regard to those lower 4 pins.
analog_world



Joined: 16 Sep 2008
Posts: 26

View user's profile Send private message

PostPosted: Sun Oct 19, 2008 12:37 am     Reply with quote

Hi PCM,
for some reason I was not successful trying to use your flex_lcd driver. Let me just give you a break down of what I did. I added the flex_lcd.c file to the project source file list. Then, I compiled the flex_lcd.c by itself, but it gives me an error saying
Code:

A #DEVICE line required before this line :
int8 const LCD_INIT_STRING[4] =" 



I am just wondering if I am doing it the right way or something is going wrong. Thank you again.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 19, 2008 1:24 am     Reply with quote

Read these links:

How to use multiple source files with MPLAB:
http://www.ccsinfo.com/forum/viewtopic.php?t=34046

More detailed information on using multiple files with MPLAB.
Read all the links in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=32221
analog_world



Joined: 16 Sep 2008
Posts: 26

View user's profile Send private message

PostPosted: Sun Oct 19, 2008 1:29 am     Reply with quote

Hi PCM,
I finally figured out that I was not including the flex_lcd.c file in the project directory. Hence, all those errors. It finally works!! . Now, I was wondering when I am trying to display received data from the GPS, how do I use this with the printf function directly. Thank you.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 19, 2008 1:42 am     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=33390
analog_world



Joined: 16 Sep 2008
Posts: 26

View user's profile Send private message

PostPosted: Sun Oct 19, 2008 12:19 pm     Reply with quote

Hi PCM,
This kind of seems redundant and I know that the search will show a lot of examples, but I am a little confused though. In my case, when I write a received GPS string to 16x2 display, it wouldn't be able to display it completely. Then how do I use the printf to be able to display the entire string in a continuous manner. (i meant to say the entire string characters).
Also, how can one control the individual characters on the LCD using printf. (use lcd_goto maybe I am just guessing). Thank you so much for your help.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 19, 2008 12:50 pm     Reply with quote

Do you need to do this ? Can't you display the output on a terminal
window instead ?

As I recall, a NMEA-0183 string can easily be 80 characters. That's
beyond the visible length of one row on a 16x2 LCD. A 16x2 LCD
does have 40 positions available per row, but most of it is off-screen.
You could write to that RAM and fill it with text, and then issue side-
scrolling commands to move the display left or right to see the entire line.
But it's still only 40 characters. You really need another method.

Basically you're talking about creating an LCD side-scrolling routine that
doesn't flicker or jump, due to excessive refreshing, and that can handle
long lines of ASCII text. That's a project just in itself. Is it necessary ?
analog_world



Joined: 16 Sep 2008
Posts: 26

View user's profile Send private message

PostPosted: Sun Oct 19, 2008 1:44 pm     Reply with quote

Hi PCM,
Basically, my ultimate goal is to display the parsed information which really shouldn't be a problem one piece at a time on the LCD. As you pointed out, it is not necessary in my case. I have always wanted to read in the characters into a array on the pic and display on the terminal. But, unfortunately I haven't been able to do that. Basically, the programmer (just a .exe program in my case) and the CCS compiler could not be integrated so that I can receive GPS strings from the serial on the board to the USART on the pic and then spit it onto the PC through the programmer. I have tried a lot but I honestly gave up not knowing how to display using the SIOW terminal in CCS. I was wondering if you knew a way to integrate and see the strings on my terminal screen. Thank you so much.

(my board is from a chinese company called QL200 from QLS electronic).
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 19, 2008 2:25 pm     Reply with quote

Download the manual for your board.
http://www.pic16.com/soft/QL200_user_a4_en.pdf
Look at page 34. There is a schematic of the serial port.
It shows a dual Dip Switch, S7. Make sure that both of those switches
are turned on. Then buy a serial port cable. Connect it between
the DB-9 connector, J12, and the COM1 connector on back of your PC.

I assume that you have a 4 MHz crystal on your board, for the 18F4550.
If you do, then compile, program, and run the code shown below.
Code:
#include <18F4550.h>
#fuses XT, NOWDT, PUT, BROWNOUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//==========================
void main()
{
char c;

while(1)
  {
   c = getc();
   putc(c);
  }

}


You said that you can't make SIOW.exe work. Then try HyperTerminal.
It comes with Windows. This thread has instructions on how to use it:
http://www.ccsinfo.com/forum/viewtopic.php?t=9253

Configure Hyperterminal configured for 9600 baud, No Parity, 8 bits,
and Com1. Connect the QL200 board to the PC with the standard serial
cable. Run the program shown above. Type characters into the
Hyperterminal window and they should be sent to the PIC, and then
sent back to the Hyperterminal window by the PIC, where they are
displayed on the screen.

If you can make that work, then you can use the serial port to send
debugging messages to the PC. It makes development a lot easier.
analog_world



Joined: 16 Sep 2008
Posts: 26

View user's profile Send private message

PostPosted: Sun Oct 19, 2008 2:36 pm     Reply with quote

Hello PCM,
yes I have a serial cable and a serial to USB to connect to my laptop ( I am running vista). But the problem I am facing is that I need the serial port for receiving GPS strings, so I am confused as to how do I make another serial port to display on the PC. That's my dilemma. Thank you.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 19, 2008 3:24 pm     Reply with quote

You could use a spare i/o pin and connect it directly to the Rx pin
the Com1 port on your PC. The Rx signal on the PC's DB-9 connector
is pin 2 on that connector. Don't make a mistake. Also, there must
be a ground connection between pin 5 on the PC's DB-9 connector and
ground on the QL200 board.

This program will send "Hello World" out pin B1 to the PC:
Code:
#include <18F4550.h>
#fuses XT, NOWDT, PUT, BROWNOUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B1, INVERT, DISABLE_INTS)

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

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

while(1);
}
analog_world



Joined: 16 Sep 2008
Posts: 26

View user's profile Send private message

PostPosted: Sun Oct 19, 2008 5:30 pm     Reply with quote

Hi PCM,
I was actually able to write from the PIC to the PC by just using the wires as you had told me. It does work wonderfully. However, for some reason now I am trying to just read in the data from GPS and dispaly it on the PC terminal. It just does not work. I am pretty sure I have everything set up right. Infact, i did search for a lot of examples on GPS and seems like I'm on the right path. I still don't understand why this does not work. I am posting my .h file first.

Code:

#include <18F4550.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTHS                    //Internal Oscillator, HS used by USB
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES NOPUT                    //No 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                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES PBADEN                   //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 MCLR                     //Master Clear pin enabled
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL1                     //No PLL PreScaler

#use delay(clock=8000000)
#use rs232(stream=GPS, baud=4800,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8, ERRORS)

#use rs232(stream = PC,baud=9600, xmit=PIN_B1, INVERT, DISABLE_INTS, ERRORS)


Now, the actual program.

Code:


/*#int_RDA
RDA_isr()
{

}*/
#include "myflex_lcd.c"

void main()
{
char c;

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   setup_timer_2(T2_DIV_BY_16,255,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF);

   lcd_init();  // Always call this first.

//lcd_putc("\fHello World\n");

while(1)
{
 
  c = fgetc(GPS);
 
  fprintf(PC,"%c",c);

};

}


Any ideas how to debug whether my USART port is working or not. Thank you.


Last edited by analog_world on Sun Oct 19, 2008 8:10 pm; edited 1 time in total
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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