// tab space = 4 /***********************************************************************/ /* */ /* FILE :main.c */ /* DATE :July 6, 2004 */ /* DESCRIPTION :Main Program */ /* */ /***********************************************************************/ #include "skp_bsp.h" // include SKP board support package /***************************** Start flash block address *****************************/ #define BLOCK_A 0x0F000 // Virtual eeprom /* Prototype declarations */ void mcu_init(void); // MCU initialization void main(void); /************************************************** Data flash erase block address **************************************************/ #define ERASE_BLOCK_A 0x0FFFE char lcd_text[9]; char * IntToAsciiDec(char * dest_string,int min_digits,unsigned int value); /****************************************************************************** Name : main Parameters : none Returns : nothing Description: Main template ******************************************************************************/ void main(void) { unsigned long faddr; unsigned int temp1; unsigned int temp2; mcu_init(); /* Initialize MCU */ ENABLE_LEDS; /* LED initialization for this demo - macro defined in skp_bsp.h */ InitDisplay(); /************************************************* Initializing the microcontroller for data logging **************************************************/ GRN_LED=LED_ON; fidr = 0x02; //m16c/62p type flash module selected pm13 = 0; cm06 = 1; //f8 cm1 = cm1|0x80; fmr01= 0; // fmr01= 1; //microcontroller ready to accept the commands pm13 also gets //automatically set fmr11= 0; fmr11= 1;//microcntroller in EW1 mode fmr02 = 0; fmr02 = 1; // disable flash memory lock bit /**************************** test code ****************************/ RED_LED=0; //temp1=123; //temp2=241; faddr = 0x0F004; *((unsigned int*)faddr) = 0x0040; *((unsigned int*)faddr) = 0x4321; faddr = 0x0F004; YLW_LED=0; while(!fmr00); RED_LED=1; temp2 = *((unsigned int*)faddr); //data that we store in the EEPROM IntToAsciiDec(lcd_text,4,faddr); DisplayString( (char)(LCD_LINE2 + 3), lcd_text); IntToAsciiDec(lcd_text,4,temp2); DisplayString( (char)(LCD_LINE1 + 3), lcd_text); fmr01= 0; pm17 = 1; // wait state } /***************************************************************************** Name: IntToAsciiDec Parameters: dest_string Pointer to a buffer will the string will reside min_digits Specifies the minimum number of characters the output string will have. Leading zeros will be written as '0' characters. Returns: A pointer to the string's NULL character in the string that was just created. Description: This function is used to convert a passed unsigned int into a ASCII string represented in base 10 decimal format. *****************************************************************************/ char * IntToAsciiDec(char * dest_string,int min_digits,unsigned int value) { const unsigned long base10[] = {1,10,100,1000,10000,100000}; unsigned int tmp; unsigned int i, total_digits = 0; char buff[5]; for(i=0;i<5;i++) { tmp = (int)( value % base10[i+1] ); value -= tmp; buff[i] = (char)( tmp / base10[i] ); buff[i] += '0'; if(buff[i] != '0') total_digits = i+1; } if( total_digits < min_digits) total_digits = min_digits; i = total_digits; while(i) { *dest_string++ = buff[i-1]; i--; } *dest_string = 0; return dest_string; }