|
|
View previous topic :: View next topic |
Author |
Message |
ericbeaugiuet
Joined: 23 Mar 2006 Posts: 3
|
rs232 problem with 18F2431 |
Posted: Mon Jul 03, 2006 12:38 pm |
|
|
I must communicate with a PC but the PC receive only 00 with this sample code on a 18F2431 and a MAX232. Can you help me please ?
#include <18F2431.h>
//#DEVICE ICD=TRUE
//#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7 )
#BYTE QEICON=0xFB6 // quadrature configure
#bit QEICONDIR=0xFB6.5
#BYTE DFLTCON=0xF60 // quadrature noise filter configure
#BYTE CAP2BUFL=0xF66 // position counter
#BYTE CAP2BUFH=0xF67
#BYTE CAP3BUFL=0xF64 //max count
#BYTE CAP3BUFH=0xF65
#include <flex_lcd.c>
unsigned int16 quadhigh=0;
#int_IC2QEI
QuadRollover()
{
// increment high bytes if + direction on interrupt, decrement if -
QEICONDIR?quadhigh++:quadhigh--;
// to see when this happens,
// I find it helpful to toggle a digital out here
}
void main()
{
signed int32 position=0;
signed int32 old_pos=0;
CAP2BUFL=0;
CAP2BUFH=0;
QEICON=24; // quad in x4 mode, resettable by maxcount
DFLTCON=49; // noise filter on QEA, QEB,, 1:2 clock
CAP3BUFL=0xFF; // set max count
CAP3BUFH=0xFF;
lcd_init();
lcd_putc("\n\rsalut\n\r");
puts( " ----------- " );
puts( " | salut | " );
puts( " ----------- " );
// enable_interrupts(INT_IC2QEI); // interrupt on maxcount or underflow
//enable_interrupts(GLOBAL);
while (1)
{ //of course, in real life, this is RTCC driven!!
// position=(CAP2BUFL+((int16)CAP2BUFH<<8));
// lcd_putc("\fcodeur =");
// if(old_pos!=position)
// {
// old_pos=position;
// printf(lcd_putc,"%6ld",old_pos);
// printf("%6ld",old_pos);
//
printf("ça marche");
}
} |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 03, 2006 1:08 pm |
|
|
Try the simple program shown below. I don't have a 18F2431, but I
do have a 18F4431, which is a similar PIC. I compiled the program
below for that PIC and tested it on a PicDem2-Plus board.
It displayed the following on my terminal window:
Code: | #include <18F2431.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//==========================
void main()
{
printf("Hello World\n\r");
while(1);
} |
I tested this with PCH vs. 3.249. |
|
|
Ttelmah Guest
|
|
Posted: Mon Jul 03, 2006 2:31 pm |
|
|
There are a number of other little comments to add.
The 'fuses' statement, must exist, unless you are setting the fuses manually when programming. It is remmed out in the original code posted.
Don't use the '?' conditional statement to try to toggle a bit. This statement is designed to return a particular value, not to branch to different code sections. In some circumstances, CCS, will evaluate both branches, and only return the one corresponding with 'true'. Hence the effect may well not be as expected (both entries may well actually be occuring, and hence the counter will not change).
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
|