Martin,
You have defined TEST and then carried out a check to see if is NOT defined. Since this must be false then the variables will not be defined.
Change the #ifndef TEST to #ifdef TEST and all should be fine.
Regards
davidb

Hi,
Problem: The following simply test code demonstrates the problem using
signed data types and the comparison if (error > limit).
Expected Behaviour: To work correctly x should be 1 less than y at the end
of the comparison loop.
If the code is compiled for a 16F887 then all works as expected with
error defined as any data type; signed char, signed short or signed long.
If the code is compiled for a 18F4520 then it fails if error is a signed short
but works correctly for signed char and signed long.
It also works correctly if the limit definition is changed to any signed data type.
#include <system.h>
static signed short error = -60;
static unsigned char x;
static unsigned char y;
#define limit -50
//signed short limit = -50;
void main()
{
for (error = -60; error < 60; error++)
{
if (error > limit) //Fails
{
x++;
}
if (error >= limit) //O.K.
{
y++;
}
}
for (;;
}
IDE: MPLAB V8.83
Compiler: SourceBoost C V7.05.1
Targets: PIC16F887, PIC18F4520
Reproducible: 100%
OS: XP Pro, Vista
Regards
davidb

Hi iiyama87,
Unfortunately you cannot directly compare a string with the contents of a string buffer.
What you need to do is create a string parser that will process data in your buffer character by character.
Try sending and detecting a single character (followed by NULL) first and build on that.
All HyperTerminal is doing is receiving and displaying what you sent character by character.
Google something like 'RS232 String Parser'.
Good luck
davidb

Spotted another one:
hundreds << 4;
tens << 4;
units << 4;
Incorrect syntax and will be optimised out
Once corrected will probably compile but whether it will do what you want is another matter!
Cheers
davidb
P.S Beat you to that one as well Reynard!

Hi LowFilter,
A few basic errors:
Use lower case for registers, port names, tris etc.
Use short NOT short int
ADRES not defined
semi-colon not required after defines
One instance of Tempo rather than tempo
Good Luck!
davidb

In case you don't know where to find it (once I spent a long time looking in the devices data sheet and it's not in there) , you can find the address that needs to used when programming the target device and wanting to write to EEPROM as part of this process in the devices "Memory Programming Specification" data sheet from Microchip.
BTW: I know this doesn't help with the 0xf000 address question.
Regards
Dave
Dave,
The specification states that:
The physical address range of the 256 byte data
memory is 0000h-00FFh. However, these addresses
are logically mapped to address 1E000h-1E1FFh in the
hex file. This provides a way of differentiating between
the data and program memory locations in this range.
The format for data memory storage is one data byte
per address location, LSb aligned.
Note that it says mapped to the HEX file address.
The hex file uses double bytes so the range 1E000h-1E1FFh gives 512 bytes for 256 bytes of EEPROM.
Halving the hex address gives us F000 - F0FF which appears to be correct.
davidb

Microchip document DS41390C defines the physical address range for EEPROM on the 16F1827 as 0x1E000 to 0x1E1FF. SourceBoost PIC16F1827.h defines _EEPROM as 0x1E000 so all would appear to be well but as you point out it doesn't seem to work in MPLAB. However, changing the definition in PIC16F1827.h to 0xf000 seems to allow it to work in MPLAB. Not sure whether it works on a real device though!
davidb

You haven't told us which part you are using or shown your variable definitions.
Also the maximum result from the ADC should only be 0x03ff.
Your code for converting adresl and adresh to 16 bits is long winded and unless both tmp_h and tmp_value_m are defined as shorts then it will not work.
If you use:
tmp_value_m = (tmp_h <<8) | tmp_l;
instead then that should work. However, the code would be more efficient if you re-define adresl as a short or alternatively use a union:
unsigned short adresult @adresl;
then simply copy the result:
tmp_value_m = adresult;
Regards
davidb

Rather a lot of code to wade through and I don't have the time so just a few comments:
I notice that in your i2c_is_data_ready() function you are clearing the SSPIF interrupt flag several times but have missed it after 'Master Write, Last Byte was Data'.
You only need to clear this flag once so re-arrange the code and do it at the beginning and remove all the other instances.
Secondly I would recommend that the slave receive function is carried out under interrupt with suitable data and address buffering rather than being polled.
I haven't used I2C with the 16F88* family but when using it with an 18F4520 I found that using set_bit(sspcon1, CKP); at the end of the interrupt
ensured that the clock line was always released thereby preventing lockups.
Regards
davidb

Mark,
For what you are trying to do you only need:
uartTxInterruptHandler();
uartRxInterruptHandler();
in your interrupt function to handle the UART.
These two functions handle the transmitting and receiving of characters to and from the PC via the UART entirely under interrupt control.
uartRx() and uartTx() are effectively getc() and putc() respectively and access the rxBuffer[] and txBuffer[] buffers used by uartRxInterruptHandler() and uartTxInterruptHandler().
In your main() to send data simply place it in the txBuffer[] using uartTx().
Any data received will be in the rxBuffer[] so before reading it using uartRx() see if there is any data in it by checking if rxCnt > 0.
How you handle the data after that is up to you!
I haven't checked the rest of your code regarding UART setup etc.
Regards
davidb

You cannot prototype an inline function.
The definition of an inline function must be made before it is first called.
Using your example:-
inline void DisableTmr2(void)
{
//
}
void main (void)
{
DisableTmr2();
..
..
for (;;)
{
}
}
Regards
davidb

In addition to the above regarding debouncing, toggling the LED etc. your code has a few basic errors for real life operation (I never use the simulator so I can't comment on that):
You have your switch on the wrong pin to use INTF - it should be on RB0 not RB1
Depending on how your switch is connected you will probably need to set the edge direction and possibly the internal pullup in OPTION_REG.
PEIE should also be set to enable the interrupts (INTCON = &d0)
Regards
davidb

After a quick glance I don't see a definition for rcif e.g. volatile bit rcif@PIR1.RCIF; or is this somewhere else?
Alternatively use something like !(test_bit(intcon,TMR0IF)) and !(test_bit(pir1,RCIF)) instead of individually mapping bits.
rcreg also needs to be read somewhere to ensure that the receive data interrupt flag is cleared.
Also how about initialising timer0 and clearing the interrupt flag tmr0if before starting the timer so you know the initial conditions?
Regards
davidb

Martin,
Shouldn't
while (Go_Done == 0);
be [/code] or
while (Go_Done != 0);
For 20MHz Oscillator try using a Tad of 16Tosc and Tacq of 4Tad
This gives an automatic 3.2uS aquisition time and 9.6uS conversion time
Regards
davidb