• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Micro Assignment 1
 

Micro Assignment 1

on

  • 323 views

Micro Assignment 1

Micro Assignment 1

Statistics

Views

Total Views
323
Views on SlideShare
319
Embed Views
4

Actions

Likes
0
Downloads
12
Comments
0

2 Embeds 4

http://babakdanyal.blogspot.com 3
http://beit1to8.blogspot.co.uk 1

Accessibility

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Micro Assignment 1 Micro Assignment 1 Document Transcript

    • ASSIGNMENT MICROCNOTROLLER Kashif Ayyaz Abbasi Reg Number : 09f-beit-58
    • Q : 1 Write a program to to out 1KHZ frequency by using CCP(compare mode) ? void interrupt(void); void main() { CCP1CON=0x02; PIR1.CCP1IF=0; PIE1.CCP1IE=1; CCPR1L=0xC4; CCPR1H=0X09; //set value (2500 dec) annd in 9c4 in HEX INTCON=0xc0; TRISC.F2=0; T1CON=0x08; INTCON.TMR1IE=1; INTCON.TMR1IF=0; TMR1L=0x00; //we set as a counter TMR1H=0X00; T1CON.TMR1ON=1; while(1){} } void interrupt(void){ if(PIR1.CCP1IF) { PIR1.CCP1IF=0; } }
    • Q: 2 Write a program to Out different Frequencies using Switch ? If Sw1==1 frequency out = 1KHZ Sw2 == 1 Frequency out = 2KHZ Sw3== 1 Frequency out = 3Khz int count = 0; void main() { TRISD.F0=0; T0CON=0x08; INTCON.TMR0IE=1; INTCON.TMR0IF=0; TMR0L=0XF0; TMR0H=0XD8; PORTD.F0=1; count=1; T0CON.TMR0ON=1; INTCON.GIE=1; TRISB.F0=1; TRISB.F1=1; TRISB.F2=1; PORTB=0X00; while(1) { if(portb.f0=1) { count=0; } if(portb.f1=1) { count=1; } if(portb.f2=1) { count=2; } } } void interrupt() { if( INTCON.TMR0IF==1) { if(count==0) { INTCON.TMR0IF=0;
    • T0CON.TMR0ON=0; PORTD.F0=0; TMR0L=0XF0; TMR0H=0XD8; T0CON.TMR0ON=1; //delay_ms(1000); / /count=1; } if(count==1) { INTCON.TMR0IF=0; T0CON.TMR0ON=0; PORTD.F0=0; TMR0L=0XE0; TMR0H=0XB1; T0CON.TMR0ON=1; //delay_ms(1000); //count=2; } else if (count==2) { INTCON.TMR0IF=0; T0CON.TMR0ON=0; PORTD.F0=1; TMR0L=0X78; TMR0H=0XEC; T0CON.TMR0ON=1; //delay_ms(1000); //count=3; } else { } } }
    • Q : 3 write a program to ON OFF LED 1SEC delay through Timer. # define led PORTD.F0 int count=0; void main (){ TRISD.F0=0; T0CON=0X08; INTCON.TMR0IE=1; INTCON.TMR0IF=0; TMR0L=0XF0; TMR0H=0XD8; led=1; INTCON.TMR0ON=1; INTCON.GIE=1; INTCON.PEIE=1; while(1){ if(count==249){ count=0; INTCON.TMR0ON=0; TMR0L=0XF0; TMR0H=0XD8; led=~led; delay_ms(1000); INTCON.TMR0ON=1; //INTCON.TMR0IF=0;
    • } } } void interrupt() { if(INTCON.TMR0IF){ INTCON.TMR0IF=0; INTCON.TMR0ON=0; TMR0L=0XF0; TMR0L=0XD8; count=count+1; INTCON.TMR0ON=1; } } Q: 4 write a program to transmit KICSIT on PC And receive data From PC and Display IT on LCD? unsigned char data[10]; unsigned char temp[50]; int i=0; void interrupt(void); void main() { int i,length; char X[]={"KICSIT"};
    • RCSTA=0x90; TXSTA=0X20; RCSTA.SPEN=1; Lcd_Config(&PORTD, 3,2, 0, 7, 6, 5,4); TRISD=0; PORTD=0; TRISC.F6 = 0; //TX Pin TRISC.F7 = 1; //RX Pin PIE1.RCIE=1; PIR1.RCIF=0; INTCON=0xC0; length=strlen(X); while(1){ for(i=0;i<length;i++){ TXREG=X[i]; delay_ms(1000); } lcd_out(1,1,data); } } void interrupt(void) { if(PIR1.TXIF) { PIR1.TXIF=0; } if(PIR1.RCIF==1) { data[i]= RCREG; PIR1.RCIF=0; } }
    • Q 5 : write a program to generate frequency of 4ms 8ms 2ms 4ms int count=0; void main(void){ TRISD.F0=0; T0CON=0X08; INTCON.TMR0IE=1; INTCON.TMR0IF=0; TMR0L=0XF0; TMR0H=0XD8; PORTD.F0=1; count=1; T0CON.TMR0ON=1; INTCON.GIE=1; while(1) { } } void interrupt() { if( INTCON.TMR0IF==1)
    • { if(count==0) { INTCON.TMR0IF=0; T0CON.TMR0ON=0; PORTD.F0=0; TMR0L=0XF0; TMR0H=0XD8; T0CON.TMR0ON=1; //delay_ms(1000); count=1; } if(count==1) { INTCON.TMR0IF=0; T0CON.TMR0ON=0; PORTD.F0=0; TMR0L=0XE0; TMR0H=0XB1; T0CON.TMR0ON=1; //delay_ms(1000); count=2; } else if (count==2) { INTCON.TMR0IF=0; T0CON.TMR0ON=0; PORTD.F0=1; TMR0L=0X78; TMR0H=0XEC; T0CON.TMR0ON=1; //delay_ms(1000); count=3; } else if (count==3) { INTCON.TMR0IF=0; T0CON.TMR0ON=0; PORTD.F0=0; TMR0L=0XF0; TMR0H=0XD8; T0CON.TMR0ON=1; //delay_ms(1000); count=0; } } }
    • Q : Design a control and monitoring system of turbine system Monitoring parameter are 1: temperature 2: Pressure 3: RPM sensor to measure Revolution per/min of Turbine LM35 for temperature Pressure switch for Measure pressure Frequency meter for RPM If temp> 100 || pressure switch is ON then make the turbine void setintterupt(); void ADCset(); #define turbine portb.f4 void interrupt(void); void serial_sent(float f,int a,int f); char *data_; float temp; int i,count; int result; char start; int pressure,RPM; int seccount,ExternalFreCount,Frequency=0; void serial_setting(); void serial_setting() { RCSTA=0x90; TXSTA=0X20; RCSTA.SPEN=1;
    • TRISC.F6 = 0; //TX Pin TRISC.F7 = 1; //RX Pin PIE1.RCIE=1; PIR1.RCIF=0; } void setintterupt() { INTCON=0xD0; INTCON2.INTEDG0=1; } void ADCset() { ADCON0=0x81; ADCON0.ADON=1; ADCON1=0XC0; INTCON.GIE=1; INTCON.PEIE=1; PIR1.ADIF=0; PIE1.ADIE=1; ADRESH=ADRESL=0x00; } void serial_sent(float a,int b,int f) { if(a>=100 || b==1) { turbine=1; } else { FloatToStr(a,data_); TXREG=data_; while(!TIR1.TXIF); TIR1.TXIF=0; IntToStr(b,data_); TXREG=data_; while(!TIR1.TXIF); TIR1.TXIF=0; IntToStr(f,data_); TXREG=data_; while(!TIR1.TXIF); TIR1.TXIF=0; } } void READADC(); void READADC() { ADCON0.GO_DONE=1; }
    • void timersetting(); void timersetting() { T1CON=0x08; INTCON.TMR1IE=1; INTCON.TMR1IF=0; TMR1L=0xf0; //we set as a counter TMR1H=0Xd8; T0CON=0x02; TMR0L=0x00; // we set 1 sec timer and count for 60 sec to make 1 min TMR0H=0x00; INTCON.TMR0IE=1; INTCON.TMR0IF=0; } void start_timer(); void start_timer() { T0CON.TMR0ON=1; T1CON.TMR1ON=1; } void main() { trisa.f0=1; trisb.f4=0; trisb.f0=1; UART1_Init(9600); setintterupt(); ADCset(); timersetting(); turbine=0; while(1) { if(start=='s') { READADC(); //read ADC INTCON.INTOIE=1; start_timer(); serial_sent(temp,pressure,Frequency); } } } void interrupt(void) { if(PIR1.RCIF==1) {
    • start= RCREG; PIR1.RCIF=0; } if(INTCON.INT0IF==1) { INTCON.INT0IF=0; pressure=1; } if(PIR1.ADIF) { PIR1.ADIF=0; result=ADRESH; result=result<<8; result=result+ADRESL; //data=result; temp=result; temp=temp*0.00488; temp=temp*1000; temp=temp/10; } if(INTCON.TMR1IF) { INTCON.TMR1IF=0; if(seccount==14999) // 249*60 =14940sec // 14999=1min { Frequency=TMR0H; Frequency=Frequency<<8; Frequency=Frequency+TMR0L; Frequency=(Frequency*65536)+ExternalFrecount; seccount=0; TMR1L=0xf0; //we set as a counter TMR1H=0Xd8; TMR0L=0x00; //we set as a Externaltimer TMR0H=0X00; T0CON.TMR0ON=1; T1CON.TMR1ON=1; } else { seccount++; TMR1L=0xf0; //we set as a counter TMR1H=0Xd8; }
    • } if(INTCON.TMR0IF) { INTCON.TMR0IF=0; ExternalFreCount++; } }