LPCX

// display 06H on LEDs

#include<LPC214x.h>
void delaysw();

unsigned int switchRead();

int main(){
while (1){
unsigned int data = switchRead(); // 0x0f
IODIR1 = IODIR1 | (0xff << 16); // make direction as output
IOSET1 = IOSET1 | (data << 16); // Writing on port 1.3 same for p0 too
delaysw();
}
}

unsigned int switchRead() {
unsigned int myportdata;
IODIR0 = IODIR0 & (0xffffff00); // make direction as input
myportdata = IOPIN0;
myportdata = myportdata & (0x000000ff); // port 1 (first 8 bits only)
return(myportdata);
}

void delaysw(){
int i;
for(i=0; i<250000; i++);
}

 

Timer////

// For a delay (1.5ms) and PLL0 (60Mhz)
#include<LPC214x.h>
void initPLL();
void delayus(int micros);

// A blink program to for 1.5ms delay
int main(){
while(1){
initPLL();
IODIR0 = IODIR0 | (0X01<< 10);
IOSET0 = IOSET0 | (0X01<< 10);
delayus(1500);
IOCLR0 = IOCLR0 | (0X01<< 10);
delayus(1500);
}
}

// CON CFG STAT FEED VPB (VPB, CPU = 60Mhz)
// P is the integer 156-320Mhz and M is M-1
void initPLL(){
PLL0CON = 0x01; // Enable not connected
PLL0CFG = 0x24; //0100100 (p and m bits)
PLL0FEED = 0xAA;
PLL0FEED = 0x55;
while((PLL0STAT & (0x01 <<10))==0); //wait
PLL0CON = 0x03; // Enable and connect
PLL0FEED = 0xAA;
PLL0FEED = 0x55;
VPBDIV = 0x01; // Set Pclk as 60Mhz
}

// CTCR TC PR TCR (TIMER with a clock of 1Mhz)
void delayus(int micros){
T0CTCR = 0X00; // Set as timer
T0PR = 59; // For 1Mhz
T0TC = 0x00; // Reset the count
T0TCR = 0X01; // Enable Timer
while (T0TC < micros); //wait
T0TCR =0x00; // Disable timer
}

 

 

///DAC

#include<LPC214x.h>
void initPLL();
void delayus(int micros);
void analogWrite (unsigned int analogdata);

unsigned int sinedata[100] = {544,
576,
608,
639,
670,
700,
729,
758,
786,
812,
838,
862,
884,
906,
925,
943,
960,
974,
987,
998,
1007,
1014,
1019,
1022,
1023,
1022,
1019,
1014,
1007,
998,
987,
975,
960,
944,
926,
906,
885,
862,
838,
813,
786,
759,
730,
701,
671,
640,
609,
577,
545,
513,
481,
449,
417,
386,
355,
325,
295,
267,
239,
212,
187,
163,
140,
119,
99,
81,
65,
50,
37,
26,
17,
10,
5,
2,
1,
2,
5,
10,
17,
26,
36,
49,
64,
80,
98,
117,
139,
161,
185,
210,
237,
265,
293,
322,
353,
383,
415,
446,
478,
510
};

// for a frequency of 666Hz (1.5ms delay)
int main(){
while(1){
int i;
for(i=0; i<100; i++){
analogWrite(sinedata[i]);
delayus(15);
}
}
}

// DAC 1 channel 10 bit Pin0.25
// DACR register 6-15 data
void analogWrite (unsigned int analogdata){ // the analog data which is given it will print that on pin
PINSEL1 = 0x0080000;
DACR = analogdata<<6; // put that analog data in DACR register
}

void initPLL(){
PLL0CON = 0x01; // Enable not connected
PLL0CFG = 0x24; //0100100 (p and m bits)
PLL0FEED = 0xAA;
PLL0FEED = 0x55;
while((PLL0STAT & (0x01 <<10))==0); //wait
PLL0CON = 0x03; // Enable and connect
PLL0FEED = 0xAA;
PLL0FEED = 0x55;
VPBDIV = 0x01; // Set Pclk as 60Mhz
}

// CTCR TC PR TCR (TIMER with a clock of 1Mhz)
void delayus(int micros){
initPLL();
T0CTCR = 0X00; // Set as timer
T0PR = 59; // For 1Mhz
T0TC = 0x00; // Reset the count
T0TCR = 0X01; // Enable Timer
while (T0TC < micros); //wait
T0TCR =0x00; // Disable timer
}

 

////ADC

#include<LPC214x.h>
void delayus();
void initPLL();
unsigned int AnalogtoDigital(); // ADC function

int main(){
initPLL();
while(1){
unsigned int adcdata = AnalogtoDigital(); // 10BIT DATA say 200
IODIR1 = IODIR1 | (0x3FF << 16); // Show data output on P1.16 to p1.26
IOSET1 = IOSET1 | (adcdata << 16);
delayus(1000);
}
}

// I am using ADC1 channel 0 which is port 0.6 3rd special operation
// I am giving 1.65 volts and res 10bit it should reply with 512
unsigned int AnalogtoDigital(){
unsigned int mydata;
IODIR0 = IODIR0 & (~(0x01 << 6));
PINSEL0 = PINSEL0 | (0x03 << 12); // Select the appropriate SP fun
AD1CR = 0x00; // Reset the control register to NIL
AD1CR = AD1CR | (0x01 << 0); // Select Channel line
AD1CR = AD1CR | (0x0D << 8); // Max clock, PCLK/4.5Mhz-1 // or 13
AD1CR = AD1CR | (0x01 << 16); // Brust BIT
AD1CR = AD1CR | (0x01 << 21); // PDN =1
AD1CR = AD1CR | (0x01 << 24); // Start of Conversion SOC
while((AD1GDR & (0X01 << 31)) == 0); // Wait till EOC
mydata = AD1GDR;
mydata = mydata >>6;
mydata = mydata & (0x3ff);
return(mydata);
}

 

void initPLL(){
PLL0CON = 0x01; // Enable not connected
PLL0CFG = 0x24; //0100100 (p and m bits)
PLL0FEED = 0xAA;
PLL0FEED = 0x55;
while((PLL0STAT & (0x01 <<10))==0); //wait
PLL0CON = 0x03; // Enable and connect
PLL0FEED = 0xAA;
PLL0FEED = 0x55;
VPBDIV = 0x01; // Set Pclk as 60Mhz
}

// CTCR TC PR TCR (TIMER with a clock of 1Mhz)
void delayus(int micros){
T0CTCR = 0X00; // Set as timer
T0PR = 59; // For 1Mhz
T0TC = 0x00; // Reset the count
T0TCR = 0X01; // Enable Timer
while (T0TC < micros); //wait
T0TCR =0x00; // Disable timer
}

 

 

 

 

 

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *