I am trying IAP for LPC2148. I referred its manual.I have written this program, but it is not working.
#include <lpc214x.h> #include <stdio.h> #define radd 0x40000100 void hex_asc(unsigned int); void lcd_init(); void delay(); void datar(); void comdr(); void ramclear(); void space24(); void display(); void main1(); char comd,data; char k; char i,*p,*s; typedef void (*IAP)(unsigned int [],unsigned int []); IAP iap_bypointer; void iap_byfunction (unsigned *cmd,unsigned *rslt,unsigned entry); unsigned command[5]; unsigned result[5]; char Ram_Arry[] = "12345 67890"; char *Ram_Pointer; void main () //Compile this in ARM instruction set { unsigned char index; int count=50000; iap_bypointer = (IAP) 0x7FFFFFF1; //set IAP entry address in function pointer Ram_Pointer = 0x40000100; //Set pointer to RAM for (index = 0; index<0x0B; index++) //Copy data to be written to flash into the RAM { *Ram_Pointer = Ram_Arry[index]; Ram_Pointer++; } command[0] = 0x36; //command code for "Read part ID" iap_byfunction(command,result,0x7FFFFFF0); //Call IAP functions by function method command[0] = 50; //Prepare sector five for a write operayion command[1] = 5; command[2] = 5; iap_bypointer(command,result); command[0] = 52; //erase sector five command[1] = 5; command[2] = 5; command[3] = 12000; //Cclk == 12Mhz Pll is disabled in startup code iap_bypointer(command,result); command[0] = 50; //Prepare sector five for a write operayion command[1] = 5; command[2] = 5; iap_bypointer(command,result); command[0] = 51; //write 512 bytes from address 0x40000100 command[1] = 0x0000A000; //to 0x0000A000 in flash memory; command[2] = 0x40000100; command[3] = 512; command[4] = 12000; // see erase comment above iap_byfunction(command,result,0x7FFFFFF0); while(count>0) { count--; } main1(); } void iap_byfunction (unsigned *cmd,unsigned *rslt,unsigned entry) __thumb //compile this in Thumb instruction set { __asm { mov r15,r2; } //move entry address into PC } void main1() { unsigned int j; IO1DIR=0X00FF0000; //pins 1.16 to 1.23 output pins IO0DIR=0X00000C00; //port 0 rs and en as output IO0CLR=0X00FF0000; lcd_init(); ramclear(); p=radd; s=0x0000a000; for(i=0;i<11;i++) { *p=*s; j=*p; hex_asc(j); p++; s++; } //display(); } void display() { p = radd; for(i=0;i<16;i++) { data=*p; datar(); p++; } space24(); for(i=0;i<11;i++) { data=*p; datar(); p++; } space24(); } void lcd_init() { comd=0x30; // FUNCTION SET comdr(comd); comd=0x30; comdr(comd); comd=0x30; comdr(comd); comd=0x38; //2 line,5*7 matrix comdr(comd); comd=0x06; //automatic rt shift cursor comdr(comd); comd=0x0C; //display on cursor on comdr(comd); comd=0x01; //clear display comdr(comd); } void datar() { IO1CLR=0X00FF0000; IO1SET=data<<16; IO0SET=0X00000800; //RS=1 IO0SET=0X00000400; //EN=1 delay(); IO0CLR=0X00000400; //EN=0 } void comdr() { IO1CLR=0X00FF0000; IO1SET=comd<<16; IO0CLR=0X00000800; //RS=0 IO0SET=0X00000400; //EN=1 delay(); IO0CLR=0X00000400; //EN=0 } void delay() { int loop=200000; while (loop--); } void space24() { for(i=0;i<24;i++) { data=0x20; datar(); } } void ramclear() { p=radd; for(i=0;i<32;i++) { *p=0x20; p++; } } void hex_asc(unsigned int x) { unsigned int y,z,tmp; tmp=x; y=(tmp & 0xF0); y=y>>4; if(y<=9) { y=y+0x30; } else { y=y+0x37; } datar(y); tmp=x; z=(tmp & 0x0F); if(z<=9) { z=z+0x30; } else { z=z+0x37; } datar(z); }
I want to display stored data on LCD.
What can be problem?