#include void GPIO0_Init(void) { //LPC_SC->PCONP = LPC_SC->PCONP | 0x0708829E; /* enable power to IOCON */ //P0.0 - can_RD1, P0.1 - CAN_TD1 LPC_IOCON->P0_0 = 0x00000001; /* Pin P0.0 used as CAN RX1 */ LPC_IOCON->P0_1 = 0x00000001; /* Pin P0.1 used as CAN TX1 */ //P0.2 - U0_TXD, P0.3 - U0_RXD LPC_IOCON->P0_2 = 0x00000001; /* Pin P0.2 used as TXD0 */ LPC_IOCON->P0_3 = 0x00000001; /* Pin P0.3 used as RXD0 */ //P0.4, P0.5 as GPIOS LPC_IOCON->P0_4 = 0x00000000; LPC_IOCON->P0_5 = 0x00000000; LPC_IOCON->P0_6 = 0x00000000; LPC_IOCON->P0_7 = 0x00000000; LPC_IOCON->P0_8 = 0x00000000; LPC_IOCON->P0_9 = 0x00000000; //P0.10 - U2_TXD, P0.11 - U2_RXD LPC_IOCON->P0_10 = 0x00000001; /* Pin P0.10 used as RS422_TX2_DD */ LPC_IOCON->P0_11 = 0x00000001; /* Pin P0.11 used as RS422_RX2_DD */ //P0.12, P0.13 as GPIOS LPC_IOCON->P0_12 |=0; // new port assigned for WE LPC_GPIO0->DIR |= (1<<12); //LPC_GPIO0->SET |= (1<<12); LPC_IOCON->P0_13 = 0x00000000; LPC_GPIO0->DIR |= (1<<13); LPC_IOCON->P0_14 = 0x00000000; LPC_IOCON->P0_15 = 0x00000000; LPC_IOCON->P0_16 = 0x00000000; LPC_IOCON->P0_17= 0x00000000; LPC_IOCON->P0_18= 0x00000000; LPC_IOCON->P0_19 = 0x00000000; LPC_IOCON->P0_21 = 0x00000000; LPC_IOCON->P0_22 = 0x00000000; LPC_IOCON->P0_23 = 0x00000000; LPC_IOCON->P0_24 = 0x00000000; LPC_IOCON->P0_25 = 0x00000000; LPC_IOCON->P0_26 = 0x00000000; LPC_IOCON->P0_27 = 0x00000000; LPC_GPIO0->DIR |= (1<<27); LPC_IOCON->P0_28 = 0x00000000; LPC_IOCON->P0_29 = 0x00000000; LPC_IOCON->P0_30 = 0x00000000; LPC_IOCON->P0_31 = 0x00000000; } //GPIO PORT 1 - Initialisation void GPIO1_Init(void) { ///////////////////////////////////// //P1.0 AS ETHERNET TRANSMIT DATA0 LPC_IOCON->P1_0 = 0x00000001; //P1.1 PIN AS ETHERNET DATA1 LPC_IOCON->P1_1 = 0x00000001; //P1.2 PIN AS GPIO LPC_IOCON->P1_2 = 0x00000000; //P1.4 PIN AS ETHERNET TRANSMIT DATA ENABLE LPC_IOCON->P1_4 = 0x00000001; //P1.5 PIN AS GPIO LPC_IOCON->P1_5 = 0x00000000; //P1.7 PIN AS GPIO LPC_IOCON->P1_7 = 0x00000000; //P1.8 PIN AS GPIO FOR ETHERNET CARRIER SENSE LPC_IOCON->P1_8 = 0x00000001; //P1.9 PIN AS ETHERNET RECEIVE DATA0 LPC_IOCON->P1_9 = 0x00000001; //P1.10 PIN AS ETHERNET RECEIVE DATA1 LPC_IOCON->P1_10 = 0x00000001; LPC_IOCON->P1_12 |=0; LPC_GPIO1->DIR |= (1<<12); //P1.14 PIN AS ETHERNET RECEIVE ERROR LPC_IOCON->P1_14 = 0x00000001; //P1.15 PIN AS ETHERNET RECEIVE CLK LPC_IOCON->P1_15 = 0x00000001; //P1.16 PIN AS ETHERNET MIIM CLK LPC_IOCON->P1_16 = 0x00000001; //P1.17 PIN AS ETHERNET MIIM DATA INPUT AND OUTPUT LPC_IOCON->P1_17 = 0x00000001; //BELOW PIN AS GPIO LPC_IOCON->P1_18 = 0x00000000; LPC_IOCON->P1_19 = 0x00000000; LPC_IOCON->P1_20 = 0x00000000; LPC_IOCON->P1_21 = 0x00000000; LPC_IOCON->P1_22 = 0x00000000; LPC_IOCON->P1_23 = 0x00000000; LPC_IOCON->P1_24 = 0x00000000; LPC_IOCON->P1_25 = 0x00000000; LPC_IOCON->P1_26 = 0x00000000; LPC_IOCON->P1_28 = 0x00000000; LPC_IOCON->P1_29 |=0; LPC_GPIO1->DIR |= (1<<29); LPC_IOCON->P1_30 |= 0; // Start of Conversion given LPC_GPIO1->DIR |= (1<<30); // LPC_IOCON->P1_30 = 0x00000000; } //GPIO PORT 2 - Initialisation void GPIO2_Init(void) { ////////////////////////////////////// //P2.0 AS GPIO FOR cs1 //LPC_IOCON->P2_0 =0x00000000; //LPC_GPIO2->DIR |= (1<<0); // LPC_GPIO2->SET |= (1<<0); //P2.1 AS GPIO FOR ID0 LPC_IOCON->P2_1 = 0x00000000; //P2.2 AS GPIO FOR ID1 LPC_IOCON->P2_2 = 0x00000000; //P2.3 AS GPIO FOR SPARE_DO1-P LPC_IOCON->P2_3 = 0x00000000; //P2.4 AS GPIO FOR SPARE_DO2-P LPC_IOCON->P2_4 = 0x00000000; //P2.5 AS GPIO FOR HL1 LPC_IOCON->P2_5 = 0x00000000; //P2.6 AS GPIO FOR HL2 LPC_IOCON->P2_6 = 0x00000000; //P2.7 AS GPIO FOR POST-1 LPC_IOCON->P2_7 = 0x00000000; //P2.8 AS GPIO FOR PILOT SELECTION-P LPC_IOCON->P2_8 = 0x00000000; //P2.9 AS GPIO FOR WOW-P LPC_IOCON->P2_9 = 0x00000000; //P2.10 AS GPIO PROG LPC_IOCON->P2_10 =0x00000000; //P2.11 AS GPIO WDI FROM LPC LPC_IOCON->P2_11 =0x00000000; //P2.14 AS GPIO CS-ADC-2 LPC_IOCON->P2_14 |=1; // LPC_IOCON->P2_14 |=0; // LPC_GPIO2->DIR |= (1<<14); //P2.15 AS GPIO NVSRAM CS-1 LPC_IOCON->P2_15 =1; //P2.16 AS GPIO EPL1 LPC_IOCON->P2_16 =0x00000000; //P2.17 AS GPIO EPL2 LPC_IOCON->P2_17 =0x00000000; //P2.20 AS NVSRAM CS-2-LPC LPC_IOCON->P2_20 =0x00000000; //P2.23 AS GPIO ENGINE FAIL_FB_P LPC_IOCON->P2_23 =0x00000000; //P2.24 AS GPIO FSOV_FB_P LPC_IOCON->P2_24 =0x00000000; //P2.25 AS GPIO 0SOV_FB_P LPC_IOCON->P2_25 =0x00000000; //P2.26 AS GPIO IGN_FB_P LPC_IOCON->P2_26 =0x00000000; //P2.27 AS GPIO ASOV_FB_P LPC_IOCON->P2_27 =0x00000000; //P2.28 AS GPIO READY_FB_P LPC_IOCON->P2_28 =0x00000000; //P2.29 AS GPIO MAIN PROCESSOR FAIL_FB_P LPC_IOCON->P2_29 =0x00000000; //P2.30 AS SDA FOR EEPROM LPC_IOCON->P2_30 =0x00000002; //P2.31 AS SCL FOR EEPROM LPC_IOCON->P2_31 =0x00000002; } //GPIO PORT 3 - Initialisation void GPIO3_Init(void) { LPC_IOCON->P3_0 |= 1; // D0 @ P3.0 LPC_IOCON->P3_1 |= 1; // D1 @ P3.1 LPC_IOCON->P3_2 |= 1; // D2 @ P3.2 LPC_IOCON->P3_3 |= 1; // D3 @ P3.3 LPC_IOCON->P3_4 |= 1; // D4 @ P3.4 LPC_IOCON->P3_5 |= 1; // D5 @ P3.5 LPC_IOCON->P3_6 |= 1; // D6 @ P3.6 LPC_IOCON->P3_7 |= 1; // D7 @ P3.7 LPC_IOCON->P3_8 |= 1; // D8 @ P3.8 LPC_IOCON->P3_9 |= 1; // D9 @ P3.9 LPC_IOCON->P3_10 |= 1; // D10 @ P3.10 LPC_IOCON->P3_11 |= 1; // D11 @ P3.11 LPC_IOCON->P3_12 |= 1; // D12 @ P3.12 LPC_IOCON->P3_13 |= 0; // D13 @ P3.13 LPC_IOCON->P3_14 |= 0; // D14 @ P3.14 LPC_IOCON->P3_15 |= 1; // D15 @ P3.15 LPC_IOCON->P3_16 |= 1; // D16 @ P3.16 LPC_IOCON->P3_17 |= 1; // D17 @ P3.17 LPC_IOCON->P3_18 |= 1; // D18 @ P3.18 LPC_IOCON->P3_19 |= 1; // D19 @ P3.19 LPC_IOCON->P3_20 |= 1; // D20 @ P3.20 LPC_IOCON->P3_21 |= 1; // D21 @ P3.21 LPC_IOCON->P3_22 |= 1; // D22 @ P3.22 LPC_IOCON->P3_23 |= 1; // D23 @ P3.23 LPC_IOCON->P3_24 |= 1; // D24 @ P3.24 LPC_IOCON->P3_25 |= 1; // D25 @ P3.25 LPC_IOCON->P3_26 |= 1; // D26 @ P3.26 LPC_IOCON->P3_27 |= 1; // D27 @ P3.27 LPC_IOCON->P3_28 |= 1; // D28 @ P3.28 LPC_IOCON->P3_29 |= 1; // D29 @ P3.29 LPC_IOCON->P3_30 |= 1; // D30 @ P3.30 LPC_IOCON->P3_31 |= 1; // D31 @ P3.31 // //P3.0 AS D0 // LPC_IOCON->P3_0 = 1; // // //P3.1 AS D1 // LPC_IOCON->P3_1 = 1; // // //P3.2 AS D2 // LPC_IOCON->P3_2 = 1; // // //P3.3 AS D3 // LPC_IOCON->P3_3 = 1; // // //P3.4 AS D4 // LPC_IOCON->P3_4 = 1; // // //P3.5 AS D5 // LPC_IOCON->P3_5 = 1; // // //P3.6 AS D6 // LPC_IOCON->P3_6 = 1; // // //P3.7 AS D7 // LPC_IOCON->P3_7 = 1; // // //P3.8 AS D8 // LPC_IOCON->P3_8 = 1; // // //P3.9 AS D9 // LPC_IOCON->P3_0 = 1; // // //P3.10 AS D10 // LPC_IOCON->P3_10 =1; // // //P3.11 AS D11 // LPC_IOCON->P3_11 =1; // // //P3.12 AS D12 // LPC_IOCON->P3_12 =1; // // //P3.13 AS D13 // LPC_IOCON->P3_13 =1; // // //P3.14 AS BOOT0 // LPC_IOCON->P3_14 = 0; // // //P3.15 AS BOOT1 // LPC_IOCON->P3_15 = 0; // // //P3.16 AS D14 // LPC_IOCON->P3_16 =1; // // //P3.17 AS D15 // LPC_IOCON->P3_17 =1; // } //GPIO PORT 4 - Initialisation void GPIO4_Init(void) { LPC_IOCON->P4_0 |= 1; //A0 @ P4.0 LPC_IOCON->P4_1 |= 1; //A1 @ P4.1 LPC_IOCON->P4_2 |= 1; //A2 @ P4.2 LPC_IOCON->P4_3 |= 1; //A3 @ P4.3 LPC_IOCON->P4_4 |= 1; //A4 @ P4.4 LPC_IOCON->P4_5 |= 1; //A5 @ P4.5 LPC_IOCON->P4_6 |= 1; //A6 @ P4.6 LPC_IOCON->P4_7 |= 1; //A7 @ P4.7 LPC_IOCON->P4_8 |= 1; //A8 @ P4.8 LPC_IOCON->P4_9 |= 1; //A9 @ P4.9 LPC_IOCON->P4_10 |= 1; //A10 @ P4.10 LPC_IOCON->P4_11 |= 1; //A11 @ P4.11 LPC_IOCON->P4_12 |= 1; //A12 @ P4.12 LPC_IOCON->P4_13 |= 1; //A13 @ P4.13 LPC_IOCON->P4_14 |= 1; //A14 @ P4.14 LPC_IOCON->P4_15 |= 1; //A15 @ P4.15 LPC_IOCON->P4_16 |= 1; //A16 @ P4.16 LPC_IOCON->P4_17 |= 1; //A17 @ P4.17 LPC_IOCON->P4_18 |= 1; //A18 @ P4.18 LPC_IOCON->P4_19 |= 1; //A19 @ P4.19 LPC_IOCON->P4_20 |= 1; //A20 @ P4.20 LPC_IOCON->P4_21 |= 1; //A21 @ P4.21 LPC_IOCON->P4_22 |= 1; //A22 @ P4.22 LPC_IOCON->P4_23 |= 1; //A23 @ P4.23 LPC_IOCON -> P4_24 |=1; //P4.25 AS WE //LPC_IOCON -> P4_25 |=0x00000021;// original configuration that worked //LPC_IOCON -> P4_25 |=0x00000003;//pull up working //LPC_IOCON -> P4_25 |=0x00000001;//plain o/p original //LPC_IOCON -> P4_25 |=0x00000009;//pull down //LPC_IOCON -> P4_25 |=0x00000001;// testing with previuos configuration--DATA READ WRITE HAPPENING WITH CONFIGURATION ALSO LPC_IOCON -> P4_25 |=0x00000003; LPC_GPIO4->DIR |= (1<<25); LPC_GPIO4->CLR |= (1<<25); delay(); delay(); LPC_GPIO4->SET |= (1<<25); // LPC_IOCON -> P4_29 |=0; // LPC_GPIO4->DIR |= (1<<29); // LPC_IOCON -> P4_26 |=1; //P4.27 AS BLS1 LPC_IOCON -> P4_27 |=1; //P4.28 AS BLS2 LPC_IOCON -> P4_28 |=1; //P4.29 AS BLS3 //LPC_IOCON -> P4_29 =1; //P4.30 AS CS-ADC-1 LPC_IOCON -> P4_30 |=1; //LPC_GPIO4->DIR |= (1<<30); //P4.31 AS CS1 LPC_IOCON -> P4_31 |=1; // //P4.0 AS GPIO FOR A0 // LPC_IOCON -> P4_0 =1; // // //P4.1 AS GPIO FOR A1 // LPC_IOCON -> P4_1 =1; // // //P4.2 AS GPIO FOR A2 // LPC_IOCON -> P4_2 =1; // // //P4.3 AS GPIO FOR A3 // LPC_IOCON -> P4_3 =1; // // //P4.4 AS GPIO FOR A4 // LPC_IOCON -> P4_4 =1; // // //P4.5 AS GPIO FOR A5 // LPC_IOCON -> P4_5 =1; // // //P4.6 AS GPIO FOR A6 // LPC_IOCON -> P4_6 =1; // // //P4.7 AS GPIO FOR A7 // LPC_IOCON -> P4_7 =1; // // //P4.8 AS GPIO FOR A8 // LPC_IOCON -> P4_0 =1; // // //P4.9 AS GPIO FOR A9 // LPC_IOCON -> P4_9 =1; // // //P4.10 AS GPIO FOR A10 // LPC_IOCON -> P4_10 =1; // // //P4.11 AS GPIO FOR A11 // LPC_IOCON -> P4_11 =1; // // //P4.12 AS GPIO FOR A12 // LPC_IOCON -> P4_12 =1; // // //P4.13 AS GPIO FOR A13 // LPC_IOCON -> P4_13 =1; // // //P4.14 AS GPIO FOR A14 // LPC_IOCON -> P4_14 =1; // // //P4.15 AS GPIO FOR A15 // LPC_IOCON -> P4_15 =1; // // //P4.16 AS GPIO FOR 16 // LPC_IOCON -> P4_16 =1; // // //P4.17 AS GPIO FOR A17 // LPC_IOCON -> P4_17 =1; // // //P4.18 AS GPIO FOR A18 // LPC_IOCON -> P4_18 =1; // // //P4.19 AS GPIO FOR A19 // LPC_IOCON -> P4_19 =1; // // //P4.20 AS GPIO FOR A20 // LPC_IOCON -> P4_20 =1; // //// LPC_IOCON -> P4_23 =1; //// LPC_GPIO4->DIR |= (1<<23); // // // //P4.24 AS OE# // LPC_IOCON -> P4_24 =1; // //LPC_GPIO4->DIR |= (1<<24); // //LPC_GPIO4->CLR |= (1<<24); // // //P4.25 AS WE //// LPC_IOCON -> P4_25 =0; //// LPC_GPIO4->DIR |= (1<<25); //// LPC_GPIO4->SET |= (1<<25); // LPC_IOCON -> P4_29 =0; // LPC_GPIO4->DIR |= (1<<29); // // // //P4.26 AS BLS0 // LPC_IOCON -> P4_26 =1; // // //P4.27 AS BLS1 // LPC_IOCON -> P4_27 =1; // // //P4.28 AS BLS2 // LPC_IOCON -> P4_28 =1; // // //P4.29 AS BLS3 // //LPC_IOCON -> P4_29 =1; // // //P4.30 AS CS-ADC-1 // LPC_IOCON -> P4_30 =1; // // //P4.31 AS CS1 // LPC_IOCON -> P4_31 =1; // //LPC_GPIO4->DIR |= (1<<31); } //GPIO PORT 5 - Initialisation void GPIO5_Init(void) { //P5.0 AS GPIO FOR SPARE1-FB-P LPC_IOCON -> P5_0 =0x00000000; //P5.1 AS GPIO FOR SPARE2-FB-P LPC_IOCON -> P5_1 =0x00000000; LPC_IOCON->P5_4 = 0x00000000;// NEW WRITE ENABLE SIGNAL LPC_GPIO5->DIR |= (1<<4); LPC_GPIO5->SET |= (1<<4); } void GPIO_Init(void) { //CONFIGURING PIN'S AS GPIO'S GPIO0_Init(); GPIO1_Init(); GPIO2_Init(); GPIO3_Init(); GPIO4_Init(); GPIO5_Init(); } void GPIO_InputOutput(void) { LPC_GPIO0->DIR = (unsigned int )(LPC_GPIO0->DIR) | 0xE24586C6U; LPC_GPIO0->SET = (unsigned int )(LPC_GPIO0->SET) | 0xE24586C6U; LPC_GPIO1->DIR = (unsigned int )( LPC_GPIO1->DIR) | 0xFFFD00B3U; LPC_GPIO1->SET = (unsigned int )(LPC_GPIO1->SET) | 0xFFFD00B3U; LPC_GPIO2->DIR = (unsigned int )(LPC_GPIO2->DIR) | 0xC003C8F9U; LPC_GPIO2->SET = (unsigned int )(LPC_GPIO2->SET) | 0xC003C8F9U; //LPC_GPIO3->DIR = (unsigned int )(LPC_GPIO3->DIR) | 0x02000011U; //LPC_GPIO4->DIR = (unsigned int )(LPC_GPIO4->DIR) | 0xFF1FFFFFU; The Port 4 comprises of special function pins which dont require direction setting. LPC_GPIO5->DIR = (unsigned int )(LPC_GPIO5->DIR) | 0x00000000U; } // EMC INITIALIZATION void EMC_initialisation(void) { LPC_SC->PCONP |= 0x00000800; // set PCEMC bit 11 for EMC ENABLE LPC_SC->EMCDLYCTL = 0x00000000; // EMC Delay conrol register LPC_EMC->Control = 0x00000001; // EMC Control ....enable EMc by set Bit 0 LPC_EMC->Config = 0x00000000; // EMC Config...... LPC_EMC->StaticExtendedWait = 0x00000000; // EMC Config...... LPC_SC->SCS=0x00000024;// This is the original configuration that worked //LPC_SC->SCS=0x00000060; LPC_SC->EMCCLKSEL=0x00000001; //LPC_SC->CLKOUTCFG=0x00000110; LPC_EMC->StaticConfig3 = 0x00080001; //working //LPC_EMC->StaticConfig3 = 0x00080101; // Bit 1:0: 01 for 16 bit, bit 6=0 Chip Slect Low // Bit 8=0 Extended wait disabled, bit 19 Buffer disable, Bit 20=0 Write Not protected LPC_EMC->StaticWaitWen3 = 0x0000000F; // Bit Static Memory write enable delay LPC_EMC->StaticWaitOen3 = 0x0000000F; // Bit Static Memory write enable delay LPC_EMC->StaticWaitRd3 = 0x0000001F; // Bit Static Memory write enable delay LPC_EMC->StaticWaitPage3 = 0x00000000; // Bit Static Memory write enable delay LPC_EMC->StaticWaitWr3 = 0x0000001F; // Bit Static Memory write enable delay LPC_EMC->StaticWaitTurn3 = 0x0000000F; // Bit Static Memory write enable delay LPC_EMC->StaticConfig3 = 0x00080001; //LPC_EMC->StaticConfig2 = 0x00080101; // Bit 1:0: 01 for 16 bit, bit 6=0 Chip Slect Low // Bit 8=0 Extended wait disabled, bit 19 Buffer disable, Bit 20=0 Write Not protected LPC_EMC->StaticWaitWen2 = 0x0000000F; // Bit Static Memory write enable delay LPC_EMC->StaticWaitOen2 = 0x0000000F; // Bit Static Memory write enable delay LPC_EMC->StaticWaitRd2 = 0x0000001F; // Bit Static Memory write enable delay LPC_EMC->StaticWaitPage2 = 0x00000000; // Bit Static Memory write enable delay LPC_EMC->StaticWaitWr2 = 0x0000001F; // Bit Static Memory write enable delay LPC_EMC->StaticWaitTurn2 = 0x0000000F; // Bit Static Memory write enable delay LPC_EMC->StaticConfig3 = 0x00080001; //LPC_EMC->StaticConfig1 = 0x00080101; // Bit 1:0: 01 for 16 bit, bit 6=0 Chip Slect Low // Bit 8=0 Extended wait disabled, bit 19 Buffer disable, Bit 20=0 Write Not protected LPC_EMC->StaticWaitWen1 = 0x0000000F; // Bit Static Memory write enable delay LPC_EMC->StaticWaitOen1 = 0x0000000F; // Bit Static Memory write enable delay LPC_EMC->StaticWaitRd1 = 0x0000001F; // Bit Static Memory write enable delay LPC_EMC->StaticWaitPage1 = 0x00000000; // Bit Static Memory write enable delay LPC_EMC->StaticWaitWr1 = 0x0000001F; // Bit Static Memory write enable delay LPC_EMC->StaticWaitTurn1 = 0x0000000F; // Bit Static Memory write enable delay LPC_EMC->StaticConfig3 = 0x00080001; //LPC_EMC->StaticConfig0 = 0x00080101; // Bit 1:0: 01 for 16 bit, bit 6=0 Chip Slect Low // Bit 8=0 Extended wait disabled, bit 19 Buffer disable, Bit 20=0 Write Not protected LPC_EMC->StaticWaitWen0 = 0x0000000F; // Bit Static Memory write enable delay LPC_EMC->StaticWaitOen0 = 0x0000000F; // Bit Static Memory write enable delay LPC_EMC->StaticWaitRd0 = 0x0000001F; // Bit Static Memory write enable delay LPC_EMC->StaticWaitPage0 = 0x00000000; // Bit Static Memory write enable delay LPC_EMC->StaticWaitWr0 = 0x0000001F; // Bit Static Memory write enable delay LPC_EMC->StaticWaitTurn0 = 0x0000000F; // Bit Static Memory write enable delay }