Micro Assignment 2

362 views

Published on

Micro Assignment 2

Published in: Education, Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
362
On SlideShare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
20
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Micro Assignment 2

  1. 1. ASSIGNMENT BABAK DANAYAL -29 12/20/2012 MICROCONTROLLER PROGRAMS
  2. 2. OUT 1 Khz frequency using CCP Module void main() { CCP1CON=0X02; TRISC2_BIT=0; INTCON.CCP1IF=0X00; INTCON.CCP1IE=1; CCPR1L=0XE2; CCPR1H=0X04; T3CON=0XC0; TMR3L=TMR3H=0; INTCON.TMR3IF=0; INTCON.TMR3IE=1; T3CON.TMR3ON=1; } void interrupt () { if(CCP1IF) { INTCON.CCP1IF=0; } }
  3. 3. CALCULATE THE TIME PERIOD OF FREQUENCY USING EXTERNAL INTERUPT AND CCP MODULE SOFTWARE unsigned int edg_no,fq1,fq2,fq; unsigned char txt[]; sbit LCD_RS at RD3_bit; sbit LCD_EN at RD2_bit; sbit LCD_D4 at RD4_bit; sbit LCD_D5 at RD5_bit; sbit LCD_D6 at RD6_bit; sbit LCD_D7 at RD7_bit; sbit LCD_RS_Direction at TRISD3_bit; sbit LCD_EN_Direction at TRISD2_bit; sbit LCD_D4_Direction at TRISD4_bit; sbit LCD_D5_Direction at TRISD5_bit; sbit LCD_D6_Direction at TRISD6_bit; sbit LCD_D7_Direction at TRISD7_bit; void main() { Lcd_Init(); INTCON.GIE=1; INTCON.PEIE=1; PIE1.CCP1IE=1; PIR1.CCP1IF=0; TRISC2_BIT=1; CCP1CON=0X05;
  4. 4. T3CON=0XC0; TMR3L=TMR3H=0; INTCON.TMR3IF=0; INTCON.TMR3IE=1; fq=fq1=fq2=0; edg_no=1; while(1) { IntToStr(fq,txt); Lcd_Out(1,1,txt); delay_ms(200); } } void interrupt() { if(ccp1if==1&&edg_no==1) { pir1. ccp1if=0; fq1=TMR3H; delay_ms(200); fq1=fq1<<8; delay_ms(200); fq1=fq1+TMR3L; delay_ms(200); edg_no=2; TMR3L=TMR3H=0; } else if(ccp1if==1&&edg_no==2) { fq2=TMR3H; delay_ms(200); fq2=fq1<<8; delay_ms(200); fq2=fq2+TMR3L; delay_ms(200); pir1.ccp1if=0; TMR3L=TMR3H=0; edg_no=1; fq=fq2-fq1; } }
  5. 5. CALCULATE DUTY CYCLE OF PULSE SOFTWARE unsigned int edg_no,fq; unsigned char txt[]; sbit LCD_RS at RD3_bit; sbit LCD_EN at RD2_bit; sbit LCD_D4 at RD4_bit; sbit LCD_D5 at RD5_bit; sbit LCD_D6 at RD6_bit; sbit LCD_D7 at RD7_bit; sbit LCD_RS_Direction at TRISD3_bit; sbit LCD_EN_Direction at TRISD2_bit; sbit LCD_D4_Direction at TRISD4_bit; sbit LCD_D5_Direction at TRISD5_bit; sbit LCD_D6_Direction at TRISD6_bit; sbit LCD_D7_Direction at TRISD7_bit; void main() { Lcd_Init(); INTCON.GIE=1; INTCON.PEIE=1; PIE1.CCP1IE=1; PIR1.CCP1IF=0; TRISC2_BIT=1; CCP1CON=0X05;
  6. 6. T3CON=0XC0; TMR3L=TMR3H=0; PIR2.TMR3IF=0; PIE2.TMR3IE=1; fq=0; edg_no=1; while(1) { IntToStr(fq,txt); Lcd_Out(1,1,txt); delay_ms(200); } } void interrupt() { if(ccp1if==1&&edg_no==1) { pir1. ccp1if=0; edg_no=2; TMR3L=TMR3H=0; CCP1CON=0X04; } else if(ccp1if==1&&edg_no==2) { fq=TMR3H; fq=fq<<8; fq=fq+TMR3L; pir1.ccp1if=0; edg_no=1; CCP1CON=0x05; } }
  7. 7. INCREASE AND DECREASE PULSE WIDTH WITH BUTTON SOFTWARE #define s1 portb.f2 #define s2 portb.f7 unsigned int v; void main() { CCP1CON=0X02; PIE1.CCP1IE=1; PIR1.CCP1IF=1; CCPR1L=0X02; CCPR1H=0X04; TRISC2_BIT=0; INTCON.GIE=INTCON.PEIE=1; T3CON=0XC0; PIE2.TMR3IF=0; PIE2.TMR3IE; TMR3L=TMR3H=0; T3CON.TMR3ON=1; while(1) { if(s1==1) {
  8. 8. v=CCPR1H; v=v<<8; v=v+CCPR1H; v=v+0X05; CCPR1L=v; v=v>>8; CCPR1H=v; TMR3L=TMR3H=0; T3CON.TMR3ON=1; } if(s2==1) { v=CCPR1H; v=v<<8; v=v+CCPR1H; v=v-0X05; CCPR1L=v; v=v>>8; CCPR1H=v; TMR3L=TMR3H=0; T3CON.TMR3ON=1; } } } void interrupt() { if(PIR1.CCP1IF) { PIR1.CCP1IF=0; } }
  9. 9. ON OFF LED WITH 1 SEC DELAY USING TIMER SOFTWARE #define wave portd.F4 unsigned short count=0; void main() { INTCON=0XE4; T0CON=0X08; TMR0L=0X10; TMR0H=0X27; wave=0; wave=1; T0CON.TMR0ON=1; } void interrupt() { if(TMR0IF) { count++; INTCON.TMR0IF=0; if(count==25) {
  10. 10. wave=~wave; TMR0L=0X10; TMR0H=0X27; count=0; } T0CON.TMR0ON=1; } }

×