|
|
View previous topic :: View next topic |
Author |
Message |
manisha
Joined: 03 Feb 2012 Posts: 29
|
Problem with pic18f67k22 |
Posted: Sat Mar 24, 2012 7:30 am |
|
|
hai all.....
I am using PIC18f67k22 microcontroller in my project and
I have a problem in transmitting data on the Hyperterminal of PC(eg. modem). It is displaying something like «ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«Ú
I cant understand what the problem is???
I have also attached my code...Provide me a solution if there is any problem in the code...
Expecting a quick response! Code: | #include <18F67K22.h>
#fuses HSH,WDT,PUT,PROTECT,BROWNOUT,VREGSLEEP_SW
#use delay(clock=20000000)
#USE RS232(baud=9600,xmit=pin_c6,rcv=pin_c7,bits=8,stop=1,parity=n,STREAM=ZMODEM)
#use i2c(master, sda=PIN_D4, scl=PIN_D5)
#byte PORTA = 0xF80
#byte PORTB = 0xF81
#byte PORTC = 0xF82
#byte PORTD = 0xF83
#byte PORTE = 0xF84
#byte PORTF = 0xF85
#byte PORTG = 0xF86
#include<math.h>
#include<stddef.h>
#include<string.h>
#include<stdlib.h>
#include<LCDLEDOP.c>
#include<DS1307RTC.c>
#define bkbhit (next_in != next_out)
char next_in=0,next_out=0;
char buffer[1000];
char i=0;
char ch[],b[];
//unsigned int8 b[],h[],c[],d[],lsb,msb;
unsigned int16 readvalue,adchr,realtime,adctime;
char a[];
int8 buf,buf1,adcmin,c,d;
unsigned int16 ad;
#INT_RDA
void serial_isr()
{
int8 c;
buffer[next_in]=fgetc(ZMODEM);
c = next_in;
next_in = (next_in+1) % sizeof(buffer);
if(next_in == next_out)
next_in=c; // Buffer full !!
}
unsigned int8 bgetc()
{
unsigned int8 c;
while(!bkbhit);
c = buffer[next_out];
next_out = (next_out+1) % sizeof(buffer);
return c;
}
#SEPARATE
VOID init_io()
{
set_tris_a(0X00);
set_tris_b(0x00);
set_tris_c(0x80); //1000 0000
set_tris_d(0x00);
set_tris_e(0x00);
set_tris_f(0x00);
set_tris_g(0x00);
}
VOID SERVOMAX()
{
lcd_gotoxy(1,1);
printf (lcd_putc, "SERVOMAX (I) LTD");
lcd_gotoxy(1,2);
printf (lcd_putc, " Hyderabad ");
delay_ms (4000);
}
void main(){
init_io();
lcd_init();
delay_ms(500);
ds1307_init();
delay_ms(1000);
port_b_pullups (TRUE);
// enable_interrupts(INT_RDA);
// enable_interrupts(GLOBAL);
SERVOMAX();
//SETUP_WDT(WDT_ON);
while(TRUE)
{
fprintf(ZMODEM,"serial communication");
delay_ms(5000);
}
}
| [/code] |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1348
|
|
Posted: Sat Mar 24, 2012 9:16 am |
|
|
Just some quick thoughts:
You don't use ERRORS in your #use rs232() call like you should be. Probably not your problem, but might cause issues later.
I am not familiar with the 18 series, is there a reason you use "xmit=pin_c6,rcv=pin_c7" versus just "UART1"? For some reason I thought the former specified a software uart rather than using a hardware uart, but I could be wrong about that completely.
I don't think you need init_io(), just use the built in functions that CCS provides to change values (output_high() and output_low and output_float() as needed).
Start with just trying to get a basic main working:
Code: |
void main(){
delay_ms(1500);
while(TRUE){
fprintf(ZMODEM,"serial communication");
delay_ms(5000);
}
}
|
If it doesn't, check your crystal settings, the baud rate on hyperterminal, and make sure to turn off flow control to start with. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
Help us to help you |
Posted: Sat Mar 24, 2012 2:02 pm |
|
|
Like jeremiah says, reduce your code to the MINIMUM which shows the problem.
We don't want to have to wade through mountains of stuff which is not relevant.
Recieved funny characters is often a sign of incorrect baud rates.
And yes include ERRORS in #use, unless you want to deal with them yourself.
Mike |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sat Mar 24, 2012 2:28 pm |
|
|
Also...
Do you have a MAX232 or equal logic level translation device between the PIC and the PC ?
And do you have a good ground between the two?
The 'data' you're showing us doesn't look like mismatched baudrates.
And... since you're naming the serial port stream 'ZMODEM' I have to ask.
Is Hyperterminal set for 'zmodem' protocol ? If so that is wrong !! You've got the PIC sending with NO protocol. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Mar 24, 2012 2:44 pm |
|
|
Code: | #fuses HSH,WDT,PUT,PROTECT,BROWNOUT,VREGSLEEP_SW |
Are you sure about the fuse 'HSH'? Didn't you mean 'HS'? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sat Mar 24, 2012 7:59 pm |
|
|
HSH appears to be a vaild fuse setting,as does HSM !
Shoot there's more fuse settings(+-100) than instructions !! |
|
|
manisha
Joined: 03 Feb 2012 Posts: 29
|
|
Posted: Sat Mar 24, 2012 10:54 pm |
|
|
Thanks for replies...
I have also tried reducing code and also included ERRORS in #use RS232() but the problem still persists. My second trial code is something like this.
Code: |
#include <18F67K22.h>
#fuses HSH,WDT,PUT,PROTECT,BROWNOUT,VREGSLEEP_SW
#use delay(clock=20000000)
//#USE RS232(baud=9600,xmit=pin_c6,rcv=pin_c7,bits=8,ERRORS,stop=1,parity=n,STREAM=ZMODEM)
#USE RS232(UART1,baud=9600,bits=8,ERRORS,stop=1,parity=n,STREAM=ZMODEM)
#byte PORTA = 0xF80
#byte PORTB = 0xF81
#byte PORTC = 0xF82
#byte PORTD = 0xF83
#byte PORTE = 0xF84
#byte PORTF = 0xF85
#byte PORTG = 0xF86
#include<math.h>
#include<stddef.h>
#include<string.h>
#include<stdlib.h>
#include<LCDLEDOP.c>
#SEPARATE
VOID init_io()
{
set_tris_a(0X00);
set_tris_b(0x00);
set_tris_c(0x80); //1000 0000
set_tris_d(0x00);
set_tris_e(0x00);
set_tris_f(0x00);
set_tris_g(0x00);
}
VOID DISPLAY()
{
lcd_gotoxy(1,1);
printf (lcd_putc, "Serial communication");
lcd_gotoxy(1,2);
printf (lcd_putc, " ");
delay_ms (4000);
}
void main(){
delay_ms(1500);
init_io();
lcd_init();
delay_ms(500);
DISPLAY();
while(TRUE)
{
fprintf(ZMODEM,"RS232 communication");
delay_ms(5000);
}
}
|
HS fuse shows some error and HSH is a valid fuse. And also I have MAX232 level conversion between PIC and PC. But still the problem exists. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sun Mar 25, 2012 6:02 am |
|
|
Have you confirmed that your processor is running at the correct speed?
Try this in your while loop:
Code: | while(TRUE)
{
output_toggle(pin of your choosing);
delay_ms(500);
// fprintf(ZMODEM,"RS232 communication");
// delay_ms(5000);
}
|
Is the pin high for 1/2 second then low for 1/2 second? _________________ Google and Forum Search are some of your best tools!!!! |
|
|
manisha
Joined: 03 Feb 2012 Posts: 29
|
|
Posted: Sun Mar 25, 2012 6:08 am |
|
|
Haii all.....
Today I came to conclusion that there is a problem with external oscillator or else with fuses,because when I set internal oscillator by using fuse "INTRC" I am able to display the correct data.
But externally there is no problem in hardware upto my knowledge because I have replaced other crystals and also tried with 4MHz and 20MHz ... and used fuses like HSM,WDT,PUT,PROTECT,BROWNOUT,VREGSLEEP_SW.The problem still exists..
I think, there is a necessity to change OSCCON register value but how to set that in PICC compiler.?
If any ideas please suggest.......
Expecting a quick response!!!!!! |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
Internal RC |
Posted: Mon Mar 26, 2012 3:22 pm |
|
|
I don't have latest compiler.
You will find the syntax to change oscillator frequency in the appropriate .h file of the devices folder.
Do a search for INTERNAL RC or setup_oscillator(). You should find the correct commands there.
With a valid #USE DELAY() fuse, the oscillator should run at the specified frequency, without the need for code.
Failing that, read the microchip manual and work directly on the registers (not CCS recommended).
Mike |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Tue Mar 27, 2012 6:52 am |
|
|
Quote: | «ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«ÚÛîyÚj7«Ú |
hmm... seems like a missmatched baud rate...
check your hyperterminal settings..
G _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
Oscillators |
Posted: Tue Mar 27, 2012 8:15 am |
|
|
Quote: | Today I came to conclusion that there is a problem with external oscillator or else with fuses,because when I set internal oscillator by using fuse "INTRC" I am able to display the correct data.
But externally there is no problem in hardware upto my knowledge because I have replaced other crystals and also tried with 4MHz and 20MHz ... and used fuses like HSM,WDT,PUT,PROTECT,BROWNOUT,VREGSLEEP_SW.The problem still exists..
|
If your external oscillators are not running properly, then you COULD get the illuson of incorrect baud rates.
Are you setting up with good layout, and recommended capacitors & resistor.
Having set up with a crystal, what happens if you attempt to do a simple 1Hz LED flasher?
Mike |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Tue Mar 27, 2012 8:18 am |
|
|
Just 'FYI', the 'HSH' and 'HSM' fuse options give the 'HS oscillator High power', and 'medium power' options. Pretty logical once you work this out.
Should be HSH (not HSM) for a 20MHz crystal.
Now, other things that should be set to avoid problems.
NOPLLEN, NOFCMEN, NOIESO, NOXINST
and another key one, _NOWDT_.
You have the watchdog enabled, and are not resetting it.
Realistically, don't enable 'PROTECT', when working on code. Pointless till you have it working.
Also just try putting as the first line in the code:
setup_oscillator(OSC_NORMAL);
which will ensure one of the other optional settings is not being selected by accident.
Best Wishes |
|
|
|
|
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
|