i'm using AnalogDevicesuC 812. If i'm don't mistake, I have an external memory on this ev. board. I try do based use in this xdata but don't succsess.
memcpy (data_buffer, "DATA Buffer....", sizeof (data_buffer)); memcpy (xdata_buffer, "XDATA Buffer....", sizeof (xdata_buffer)); printf(data_buffer); printf(xdata_buffer);
data_buffer has been ok, but xdata_buffer printed garbage...
maybe I need do some change in my ADuC812 board or do a change in keil propities?
This is the code now:
/************* Header files ****************************************************/ #include "ADuC812.H" // Header file for the ADuC812 MCU #include <STDIO.H> // Standard I/O header file #include <STRING.H> sbit P3_4 = 0xB4; unsigned char xdata xdata_buffer [16]; unsigned char data data_buffer [16] _at_ 0x60; int num; unsigned char interupt1 = 0; #define LED P3_4 // LED Output void initialize_system (void); void ex0_isr (void) interrupt 0 { interupt1 = 1; } /************* MAIN C Function *************************************************/ void main (void) { //flash_erase_all (); initialize_system(); // apply start setting for connect with HyperTerminal num = 3; memcpy (data_buffer, "DATA Buffer....", sizeof (data_buffer)); memcpy (xdata_buffer, "XDATA Buffer....", sizeof (xdata_buffer)); while (1) { if(interupt1==1){ printf("a"); num++; printf("%d", num); if(num%2==0){ LED ^= -1; } interupt1=0; printf(data_buffer); printf(xdata_buffer); } } } void initialize_system (void) { // Initialize the serial port (9600, 8, N, 1) [see page 32 of data sheet] PCON &= 0x7F; // Clear bit 7 of the PCON register (SMOD1 = 0) SCON = 0x50; // 0101,0000 (Mode 1 and RxD enable) TMOD |= 0x20; // Timer #1 in autoreload 8 bit mode TCON = 0x40; // Set Timer #1 to run mode TH1 = 0xFA; // Baud rate is determined by // Timer #1 overflow rate // Baud Rate = (Fcpu / 384) / (256 - TH1) // Fcpu = 11.0592 MHz // TH1 = FD = 253 -> Baud Rate = 9600 // TH1 = FA = 250 -> Baud Rate = 4800 TR1 = 1; // Turn on Timer 1 TI = 1; // Set UART to send first char IT0 = 1; // Configure interrupt 0 for falling edge on /INT0 (P3.2) EX0 = 1; // Enable EX0 Interrupt EA = 1; // Enable Global Interrupt Flag return; }
The core problem here is a buffer overrun. Check how much memory your strings actually consume, and how big your arrays are. Your string written to xdata lacks the terminating '\0'. Bad mojo.
And two more things: don't use printf() where fputs() would suffice, and absolutely don't use it without a format string.