Jump to content
Remi Sans Famille

18F4680 Some Strange Things

Recommended Posts

corrigendum: 16F887 should be 16F877, line 5
Hi guys,
I found some irregularities which I cannot explain. Perhaps it's the programmer (Velleman VM134=K8076) that I bought because I have to wait for the second EBlock 006, already ordered. The old EB006 also gave problems with the 18F4680.
What happened? I had no difficulties at all programming a 16F877. But when I loaded the same program (mutatis mutandis) in a 18F4680 some strange things happen.
Example A.
It doesn't like if arrays are addressed directly. For instance:
LcdBuffer[5] = 'A'; has no effect at all.
I have to use a variable, so:
char i;
i = 5;
LcdBuffer = 'A';
Which is understood.

 

Example B.
If I declare three const arrays of char then the order seems to be important.
const char HexSigns[] = "0123456789ABCDEF";
const char CompasText[] = "From compas";
const char GPSText[] = "From GPS";
produces nonsense with HexSigns. I have to do it like:
const char CompasText[] = "From compas";
const char GPSText[] = "From GPS";
const char HexSigns[] = "0123456789ABCDEF";
Same lines, different order.
I tried both examples out several times because I searched the fault in my own program of course. Perhaps it's the compiler, but I am not sure about that. I suppose that there are complications when indexing. Hopefully the EB006 arrives soon. What can it be?
Remi
Edited by Remi Sans Famille

Share this post


Link to post
Share on other sites

Remi,

 

 

Hi guys,
I found some irregularities which I cannot explain. Perhaps it's the programmer (Velleman VM134=K8076) that I bought because I have to wait for the second EBlock 006, already ordered. The old EB006 also gave problems with the 18F4680.
What happened? I had no difficulties at all programming a 16F887. But when I loaded the same program (mutatis mutandis) in a 18F4680 some strange things happen.
Example A.
It doesn't like if arrays are addressed directly. For instance:
LcdBuffer[5] = 'A'; has no effect at all.
I have to use a variable, so:
char i;
i = 5;
LcdBuffer = 'A';
Which is understood.

 

Example B.
If I declare three const arrays of char then the order seems to be important.
const char HexSigns[] = "0123456789ABCDEF";
const char CompasText[] = "From compas";
const char GPSText[] = "From GPS";
produces nonsense with HexSigns. I have to do it like:
const char CompasText[] = "From compas";
const char GPSText[] = "From GPS";
const char HexSigns[] = "0123456789ABCDEF";
Same lines, different order.
I tried both examples out several times because I searched the fault in my own program of course. Perhaps it's the compiler, but I am not sure about that. I suppose that there are complications when indexing. Hopefully the EB006 arrives soon. What can it be?
Remi

 

Your problems are unexpected.

Please provide a small but complete program demonstrating the issue then we can take a look.

 

Regards

Dave

Share this post


Link to post
Share on other sites
Corrigendum:

"]" added at line:

SerialMessageToPC("]\n\r"); //on screen PC: "ab+d++++]" instead of: "abcd++++]"

 

Hello Dave, thank you for your interest.
I stripped as much as I could from the program but not things from which I think they can cause problems.
Nevertheless there are 92 lines.
The "rubbish" my program produces is old information which has been left in the controller.
Here you go:
#include <system.h> // stripped version, controller=18F4680, from Remi Sans Famille.
#define slaveCMPS10_ADRES_0xC0 0xC0
#define slaveLCD_ADDRESS_0x50 0x50
#define slaveGPS_ADDRESS_0x40 0x40
#define MasterInputSize_43 43
#define LcdSize_32 32
#pragma CLOCK_FREQ 20000000
#pragma DATA _CONFIG1H, 0b11000010
#pragma DATA _CONFIG2L, 0b00011111
#pragma DATA _CONFIG2H, 0b00011111
#pragma DATA _CONFIG3H, 0b10000100
#pragma DATA _CONFIG4L, 0b11000101
#pragma DATA _CONFIG5L, 0b00001111
#pragma DATA _CONFIG5H, 0b11000000
#pragma DATA _CONFIG6L, 0b00001111
#pragma DATA _CONFIG6H, 0b11100000
#pragma DATA _CONFIG7L, 0b00001111
#pragma DATA _CONFIG7H, 0b01000000
#pragma DATA WDTCON, 0b00000001
//-----------------------------------------------------------------------------------------------
const char HexSigns[] = "0123456789ABCDEF";
const char CompassText[] = "< van kompas >";
const char GPSText[] = "< van GPS >";
char LcdBuffer32[LcdSize_32 + 1] = "++++++++++++++++++++++++++++++++";
unsigned char ReceivedByte = 0;
unsigned char MasterInputBuffer[MasterInputSize_43 + 1];
//-----------------------------------------------------------------------------------------------
void initialise(void)
{
trisb = 0b11111101;
spbrg = 129; //baud rate generator register, 129 -> 9600 baud at 20 Mhz
txsta = 0b00100100;
rcsta = 0b10010000;
pie1 = 0b00101000;
t1con = 0b00010001;
intcon = 0b11000000;
sspcon1 = 0b00111000;
}
//-----------------------------------------------------------------------------------------------
void interrupt(void)
{
if (test_bit(pir1,RCIF)) ReceivedByte = rcreg; //clear flag
if (test_bit(pir1,SSPIF)) clear_bit(pir1,SSPIF); //clear flag
if (test_bit(pir2,BCLIF)) clear_bit(pir2,BCLIF); //clear flag
}
//-----------------------------------------------------------------------------------------------
void SerialMessageToPC(char *p) //9600 Bd, PC displays the message
{
while (*p != '\0')
{
while (!test_bit(pir1,4));
txreg = *p; //send to max232, text will displayed by PC
p++;
}
while (!test_bit(pir1,4));
}
//-----------------------------------------------------------------------------------------------
void AskCMPS10Compass(void)
{
unsigned char i;
for (i = 0; i < LcdSize_32; i++)
{
LcdBuffer32 = '+';
}
i = 0; LcdBuffer32 = 'a';
i = 1; LcdBuffer32 = 'b';
LcdBuffer32[2] = 'c'; /* [2] !! */
i = 3; LcdBuffer32 = 'd';
i = 8; LcdBuffer32 = '\0';
SerialMessageToPC(LcdBuffer32);
SerialMessageToPC("]\n\r"); //on screen PC: "ab+d++++]" instead of: "abcd++++]"
}
//-----------------------------------------------------------------------------------------------
void main(void)
{
const char Hopla[] = "Hopla";
initialise();
while (1)
{
AskCMPS10Compass(); delay_ms(255);
SerialMessageToPC(HexSigns); SerialMessageToPC("\n\r"); // rubbish on screen
SerialMessageToPC(CompassText); SerialMessageToPC("\n\r"); // rubbish on screen
SerialMessageToPC(GPSText); SerialMessageToPC("\n\r"); // rubbish on screen
SerialMessageToPC(Hopla); SerialMessageToPC("\n\r"); // rubbish on screen
delay_ms(255); delay_ms(255);
portb.1 ^= 1; //heartbeat, LED is connected, works fine
}
}
//----------------------------------- the end ----------------------------------------------------
Edited by Remi Sans Famille

Share this post


Link to post
Share on other sites

Hi Dave,

 

It is very silent round my little problem. I have been experimenting a lot because I thought that my configuration bits were not OK. But I have not been able to detect faults in my program yet. Hopefully you will find the time to have another look at it and perhaps inform me what I have to alter to make it working. Helas the 16F877 is to small for my purpose, that's why I bought several 18F4680's which are still unused. Please help.

Sincerely, Remi

Share this post


Link to post
Share on other sites

Hi Remi,

 

Your config 4L has extended instruction set enabled. This is not supported in SourceBoost. :(

 

Use the type 2 config options they are much easier to read for anyone looking at your code.

//#pragma  DATA _CONFIG4L,        0b11000101
#pragma config DEBUG = OFF // Background debugger disabled, RB6 and RB7 configuredas general purpose I/O pins
#pragma config XINST = OFF // Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
#pragma config BBSIZ = 1024 // 1K words (2K bytes) Boot Block
#pragma config LVP = ON // Single-Supply ICSP enabled
#pragma config STVREN = ON // Stack full/underflow will cause Reset

You are running with watchdog enabled, but nothing to reset it.

I assume your programmer uses low voltage programming.

 

The spec says set the Tx output pin to an output (trisc.6 = 0).

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

Come Awa ' In

 

Well Reynard, thanks a lot!!

Like you wrote, it appeared to be the _CONFIG4L extended enable instruction.

I will now meticulously go into the configuration bits. I want to know all about it, it's the base.

 

What I tried before, was skipping /* commenting out */ that special line, but strangely(!) enough the controller seems to remember previous settings. The Velleman VM134 programmer has the option to erase the PIC firstly. There are a lot of variables to set and variable methods, when combined make a lot of different ways. But for me the main reassurance is that the sourceboost compiler is OK.

Which is my best Santa Claus (in Holland 5 December) present ever.

 

Again thanks,

Remi

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×