Posts

Exp. 7.: On-chip ADC Programming in LPC2148 Development Board.

Image
  CODE #include <lpc214x.h> void delay(unsigned char time) {     unsigned int i, j;     for (j = 0; j < time; j++) {         for (i = 0; i < 8000; i++);     } } void LCD_command(unsigned char command) {     IOCLR0 = 0xFF << 16; // Clear LCD Data lines     IOCLR1 = 1 << 16; // RS=0 for command     IOCLR1 = 1 << 17; // RW=0 for write     IOSET0 = command << 16; // put command on data line     IOSET1 = (1 << 18); // en=1     delay(10); // delay     IOCLR1 = (1 << 18); // en=0 } void LCDdata(unsigned char data) {     IOCLR0 = 0xFF << 16; // Clear LCD Data lines     IOSET1 = 1 << 16; // RS=1 for data     IOCLR1 = 1 << 17; // RW=0 for write     IOSET0 = data << 16; // put command on data line     IOSET1 = (1 << 18); // en=1     delay(...

EXP.6: GPS Module Interfacing with LPC2148 Development Board.

Image
CODE #include <lpc214x.h> // Define Clock settings #define PCLK 15000000 #define BAUDRATE 9600 // Set Baud Rate here void delay(unsigned int time) {     unsigned int i, j;     for (j = 0; j < time; j++)     {         for (i = 0; i < 8000; i++);     } } void InitUART(void) {     unsigned int Baud16;     U0LCR = 0x83;     Baud16 = (PCLK / (16 * BAUDRATE));     U0DLM = Baud16 >> 8;     U0DLL = Baud16;     U0LCR = 0x03; } // Function to Transmit a character void SendByte(unsigned char data) {     U0THR = data;     while ((U0LSR & 0x40) == 0); } // Function to Receive a character unsigned char ReceivedByte() {     while ((U0LSR & 0x01) == 0);     return U0RBR; } // Function to Transmit a string void SendString(const unsigned char *str) {     while (*str != '\0')     {       ...

Expt. 5: GSM Module Interfacing with ARM7-LPC2148 for sendindSMS

Image
CODE #include <lpc214x.h> // Define Clock settings #define PCLK 15000000 #define BAUDRATE 9600 // Set Baud Rate here void delay(unsigned char time) {     unsigned int i, j;     for (j = 0; j < (unsigned int)time; j++) {         for (i = 0; i < 8000; i++) {             // Delay         }     } } // Function to Initialize the UART0 void InitUART(void) {     unsigned int Baud16;     U0LCR = 0x83;     Baud16 = (PCLK / (16 * BAUDRATE));     U0DLM = (unsigned char)(Baud16 >> 8);     U0DLL = (unsigned char)Baud16;     U0LCR = 0x03; } // Function to Transmit a byte void SendByte(unsigned char data) {     U0THR = data;     while ((U0LSR & 0x40) == 0); } // Function to Transmit a string void SendString(const unsigned char *str) {     while (*str != '\0') {         Send...

Exp.4: To control the Speed of DC motor using PWMinPIC18F

Image
CODE #include<p18f4550.h> void delay(unsigned int time) { unsigned int i, j; for(i=0;i<time;i++) for(j=0;j<1000;j++); } void main(void) { unsigned int i; TRISCbits.TRISC1 = 0; //RC1 pin as output TRISCbits.TRISC2 = 0; //CCP1 pin as output LATCbits.LATC1 = 0; CCP1CON = 0x3c; //Select PWM mode; CCPR1L = 0x0F; //Duty cycle 10%T2CON = 0x20; //Prescalar = 16; Timer2 OFF PR2 = 0x95; //Period Register TMR2ON = 1; //Timer2 ON while(1) //Loop forever { for(i=15;i<150;i++) { CCPR1L = i; delay(100); } for(i=150;i>15;i- -) { CCPR1L = i; delay(100); } } } Revised code: #include <p18f4550.h> void delay(unsigned int time) {     unsigned int i, j;     for (i = 0; i < time; i++)     {         for (j = 0; j < 1000; j++);     } } void main(void) {     unsigned int i;     TRISCbits.TRISC1 = 0; // RC1 pin as output     TRISCbits.TRISC2 = 0; // CCP1 pin as output     LATCbits.LATC...

Exp.3: Serial Communication with PIC18Fcontroller

Image
CODE #include<p18F4550.h> #include<stdio.h> #define Fosc 48000000UL void InitUART(unsigned int baudrate) { TRISCbits.RC6 = 0; //TX pin set as output TRISCbits.RC7 = 1; //RX pin set as input SPBRG = (unsigned char)(((Fosc /64)/baudrate)-1); BAUDCON = 0x00; // 8-bit baudrate generator TXSTA = 0x20; //Asynchronous 8-bit; Transmit enabled RCSTA = 0x90; //8-bit data; single receive enabled } void SendChar(unsigned char data) { while(TXSTAbits.TRMT == 0); //Wait while transmit register is empty TXREG = data; //Transmit data } void putch(unsigned char data) { SendChar(data); } unsigned char GetChar(void) { while(!PIR1bits.RCIF); //Wait till receive buffer becomes full return RCREG; //Returned received data } void main(void) { InitUART(9600); printf("\r\nHello:\r\n"); while(1) { printf("%c" ,GetChar()); //Receive character from PC and echo back } while(1); }

Exp.2: LCD interfacing with PIC18F controller

Image
CODE #include <p18f4550.h> #define EN LATAbits.LA1 #define RS LATAbits.LA0 #define LCD LATB void delay(unsigned int time) { unsigned int i , j ; for(i = 0; i < time; i++) for(j=0;j<1000; j++); } void LCDcommand(unsigned char command) { RS = 0; // RS low : Instruction LCD = command; EN = 1; // EN High delay(10); EN = 0; // EN Low delay(10); } void LCDdata(unsigned char data) { RS = 1; // RS HIGH : DATA LCD = data; EN = 1; // EN High delay(10); EN = 0; // EN Low; data sampled at EN falling edge delay(10); } void main(void) { ADCON1 = 0x0F; TRISB = 0x00; //set data port as output TRISAbits.RA0 = 0; //RS pin TRISAbits.RA1 = 0; // EN pin unsigned char *String1 = " Embeddedsystem"; LCDcommand(0x38); //8 bit mode, 2 line,5x7 dots LCDcommand(0x06); // entry mode LCDcommand(0x0C); //Display ON cursor OFF LCDcommand(0x01); //Clear display LCDcommand(0x80); //set address to 1st line while(*String1) { LCDdata(*String1); String1++; } while(