nurquhar
Joined: 05 Aug 2006 Posts: 149 Location: Redditch, UK
|
Weird printf stuff after read config memory ??? |
Posted: Sat Jul 23, 2011 3:41 am |
|
|
CCS PCM C Compiler, Version 4.123
I have the following code which is supposed to test reading the user id at 0x8000. The read_config_memory() seems to work in that it read back the correct values. But when I print the values out it seems to corrupt the printf string and I get a bunch of 10 'zeros' instead of the 10 char string.
This only happens after making the call to read_config_memory()
Is it my code or is it a compiler fault
Terminal Output
Code: |
Hello World
user id = 12
<0><0><0><0><0><0><0><0><0><0>44
<0><0><0><0><0><0><0><0><0><0>55
<0><0><0><0><0><0><0><0><0><0>66
|
The test code
Code: |
#include <12F1822.h>
#device adc=8
//////// Program memory: 2048x14 Data RAM: 112 Stack: 16
//////// I/O: 12 Analog Pins: 8
//////// Data EEPROM: 256
//////// C Scratch area: 20 ID Location: 8000
//////// Fuses: LP,XT,HS,RC,INTRC_IO,ECL,ECM,ECH,NOWDT,WDT_SW,WDT_NOSL,WDT
//////// Fuses: PUT,NOPUT,NOMCLR,MCLR,PROTECT,NOPROTECT,CPD,NOCPD,NOBROWNOUT
//////// Fuses: BROWNOUT_SW,BROWNOUT_NOSL,BROWNOUT,CLKOUT,NOCLKOUT,NOIESO
//////// Fuses: IESO,NOFCMEN,FCMEN,WRT,WRT_EECON400,WRT_EECON200,NOWRT
//////// Fuses: PLL_SW,PLL,NOSTVREN,STVREN,BORV25,BORV19,DEBUG,NODEBUG,NOLVP
//////// Fuses: LVP
////////
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOCPD //No EE protection
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOMCLR //Master Clear pin enabled
//#FUSES MCLR //Master Clear pin enabled
#FUSES PUT //Power Up Timer
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOIESO //Internal External Switch Over mode disabled
//#FUSES IESO //Internal External Switch Over mode enabled
#FUSES NOFCMEN //Fail-safe clock monitor enabled
//#FUSES NODEBUG //No Debug mode for ICD
#FUSES DEBUG //Debug mode for ICD
//#FUSES WDT_NOSL
#FUSES NOWRT //Program Memory Write Protected
//#FUSES PLL // PLL Enabled
#FUSES PLL_SW // PLL under software control, disabled
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES BORV25 //Brownout reset at 2.5V
#FUSES NOCLKOUT //Output clock on OSC2
#use delay (clock=32000000)
#use fast_io(A)
#priority timer2
// Uart TX = C4 (RXD Yellow), RX = C5 (TXD Orange)
#use rs232(UART1, baud=0,parity=N,bits=8,stop=1, errors)
#byte APFCON = getenv("SFR:APFCON")
#bit RXDTSEL = getenv("bit:RXDTSEL")
#bit TXCKSEL = getenv("bit:TXCKSEL")
#byte PR2 = getenv("SFR:PR2")
#byte PORTA = getenv("SFR:PORTA")
#byte LATA = getenv("SFR:LATA")
#bit TMR2IF = getenv("bit:TMR2IF")
// I/O Functions
#define LED_R PIN_A0
#define LED_G PIN_A1
#define LED_B PIN_A2
#define HETR PIN_A3
#define UART_TX PIN_A4
#define UART_RX PIN_A5
// Tris Reg A --543210 - 0=O/P 1==I/P
#define TRIS_A 0b00101000
typedef unsigned int8 uint8 ;
typedef unsigned int16 uint16 ;
typedef unsigned int32 uint32 ;
typedef signed int8 sint8 ;
typedef signed int16 sint16 ;
typedef signed int32 sint32 ;
#byte EEADRL = getenv("SFR:EEADRL")
#byte EEADRH = getenv("SFR:EEADRH")
#byte EEDATL = getenv("SFR:EEDATL")
#byte EEDATH = getenv("SFR:EEDATH")
#byte EECON1 = getenv("SFR:EECON1")
#bit CFGS = getenv("bit:CFGS")
#bit RD = getenv("bit:RD")
#byte EECON2 = getenv("SFR:EECON2")
#byte INTCON = getenv("SFR:INTCON")
#bit GIE = getenv("bit:GIE")
// Read config memory, address is an offeset to the 0x8000 base in the PIC
uint8 read_config_memory(uint8 address)
{
int1 ie ;
ie = GIE ;
EEADRL = address ;
EEADRH = 0 ;
CFGS = 1 ;
GIE = 0 ;
RD = 1 ;
#asm
nop
nop
#endasm
GIE = ie ;
return(EEDATL) ;
}
void main()
{
int dat ;
// Switch to internal 32Mhz Osc, ie 4xPLL x 8Mhz = 32Mhz
setup_oscillator(OSC_8MHZ | OSC_NORMAL | OSC_PLL_ON);
// Turn stuff off
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_dac(DAC_OFF);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(T0_internal);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC);
// Setup Uart
RXDTSEL = 1 ;
TXCKSEL = 1 ;
setup_uart(9600) ;
// Turn the uart on after setting the baud
setup_uart(TRUE) ;
// Set port directions for fast I/O
set_tris_a(TRIS_A) ;
// Set pullups - RA5(RX), RA3(Hall Effect Trans)
port_a_pullups(0x24) ;
// Default LED's off
output_high(LED_R) ;
output_high(LED_G) ;
output_high(LED_B) ;
delay_ms(100) ;
printf("\rHello World\r") ;
//dat = read_config_memory(0x00);
dat = 0x12 ;
printf("user id = %x\r", dat) ;
dat = read_config_memory(0x01);
printf("user id = %x\r", dat) ;
dat = read_config_memory(0x02);
printf("user id = %x\r", dat) ;
dat = read_config_memory(0x03);
printf("user id = %x\r", dat) ;
while(1) ;
}
|
|
|