Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Lab programs FOR 8TH SEM EC SUBJECT BY LOHITH KUMAR |11GUEE6018

193 vues

Publié le

Lab programs FOR 8TH SEM EC SUBJECT BY LOHITH KUMAR |11GUEE6018

Publié dans : Formation
  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

Lab programs FOR 8TH SEM EC SUBJECT BY LOHITH KUMAR |11GUEE6018

  1. 1. Buzzer: #include <lpc214x.h> #define BUZZER_ON() IO1CLR=(1<<25) #define BUZZER_OFF() IO1SET=(1<<25) #define Count 100 void Buzzer_Delay(unsigned char j); void Buzzer_Delay(unsigned char j) { unsigned int i; for(;j>0;j--) { for(i=0; i<60000; i++); } } int main(void) { PINSEL0 = 0x0000000; PINSEL1 = 0x00000000; PINSEL2 = 0x00000000; IO1DIR = (1<<25) ; while(1) { BUZZER_ON(); Buzzer_Delay(Count); BUZZER_OFF(); } }
  2. 2. LCD: #include "lcd.h" unsigned char Name[]="MyName"; unsigned char Surname[] = "Surname"; int main (void) { init_lcd(); lcd_putstring(0,Name); lcd_putstring(1,Surname); while (1) ; } -------------------------------not required to write if not asked for it------------------------------------------- #ifndef _LCD_H #define _LCD_H #define MAX_CHAR_IN_ONE_LINE 16 enum ROW_NUMBERS { LINE1, LINE2 }; void init_lcd(void); void lcd_putstring(unsigned char line, char *string); void lcd_clear(void); void lcd_backlight_on(void); int lcd_gotoxy(unsigned int x, unsigned int y); void lcd_putchar(int c); #endif
  3. 3. Down counter: #include<p24fj128ga010.h> _CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2) _CONFIG2( FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_XT & FNOSC_PRI) void delay(); int main(void) { unsigned int b=255; TRISA = 0x0000; while(1) { PORTA=b; delay(); delay(); b--; if (!b) { delay(); delay(); delay(); delay(); b = 255; } } }
  4. 4. void delay() { long int x; for(x=0;x<90000;x++); } UP counter: #include<p24fj128ga010.h> _CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2) _CONFIG2( FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_XT & FNOSC_PRI) void delay(); int main(void) { unsigned int b=1; TRISA = 0x0000; while(1) { PORTA=b; delay(); delay(); b++; if (!b) { delay();
  5. 5. delay(); delay(); delay(); b = 0x0000; } } } void delay() { long int x; for(x=0;x<90000;x++); } Left shift: #include<p24fj128ga010.h> _CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2) _CONFIG2( FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_XT & FNOSC_PRI) #define init_count 1 void delay(); unsigned int counter; int main(void) { int i; TRISA = 0x0000; counter = init_count;
  6. 6. while(1) { for(i=0;i<8;i++) { PORTA=counter; delay(); counter = counter << 1; } counter = 1; } } void delay() { long int x; for(x=0;x<90000;x++); } Right shift: #include<p24fj128ga010.h> _CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2) _CONFIG2( FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_XT & FNOSC_PRI) #define init_count 128 void delay(); unsigned int counter; int main(void)
  7. 7. { int i; TRISA = 0x0000; counter = init_count; while(1) { for(i=0;i<8;i++) { PORTA=counter; delay(); counter = counter >> 1; } counter = 128; } } void delay() { long int x; for(x=0;x<60000;x++); } Voltage converter/ADC: #include<p24fj128ga010.h> _CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2) _CONFIG2( FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_XT & FNOSC_PRI)
  8. 8. #define init_count 128 int main(void) { unsigned int ADC_Result; TRISA = 0x0000; AD1CON1 = 0x80E4; AD1CON2 = 0; AD1CON3 = 0x1F05; AD1CHS = 5; TRISBbits.TRISB2 = 1; TRISBbits.TRISB3 = 1; AD1PCFGbits.PCFG5 = 0; AD1CSSL = 0; AD1CON1bits.ADON = 1; while (1) { while(!AD1CON1bits.DONE); ADC_Result = (long) ADC1BUF0; ADC_Result >>= 7; PORTA = (0x80 >> ADC_Result); } }
  9. 9. Note: Device specific keywords in the program for ex: PORTA or TRISA etc are case sensitive. Take care to ensure the cases in the program while executing.

×