Monday, February 11, 2019
โครงงานที24
code
void beep(void);
main()
{
int time1,time2;
TRISB = 0xF0;
while(1)
{
PORTB.F1=0;
PORTB.F2=0;
PORTB.F3=0;
while(~PORTB.F4&PORTB.F5&PORTB.F6)
{
PORTB.F1=1;
PORTB.F2=0;
PORTB.F3=0;
for(time1=0;time1<20000;time1++)
{
while(PORTB.F4&~PORTB.F5&PORTB.F6)
{
PORTB.F1=1;
PORTB.F2=1;
PORTB.F3=0;
for(time2=0;time2<10000;time2++)
{
while(PORTB.F4&PORTB.F5&~PORTB.F6)
{
PORTB.F1=1;
PORTB.F2=1;
PORTB.F3=1;
beep();
Delay_ms(1000);
}
}
}
}
}
}
}
void beep(void)
{
int i ;
for(i=0;i<200;i++)
{
PORTB.F0=1;
Delay_us(200);
PORTB.F0=0;
Delay_us(200);
}
}
โครงงานที่22
code
int conv7segment(int number);
main()
{
int minute,sec;
TRISB= 0x00;
TRISA= 0x00;
CMCON= 0x07;
PORTA.F0=0;
PORTA.F1=1;
for(minute=9;minute>0;minute--)
{
PORTB = conv7segment(minute);
for(sec=0;sec<=59;sec++)
{
PORTA.F7=1;
Delay_ms(500);
PORTA.F7=0;
Delay_ms(500);
}
}
PORTB = conv7segment(0);
PORTA.F0=0;
PORTA.F1=1;
}
int conv7segment(int number)
{
switch(number)
{
case 1: return 0x06;
case 2: return 0x5b;
case 3: return 0x4f;
case 4: return 0x66;
case 5: return 0x6d;
case 6: return 0x7d;
case 7: return 0x07;
case 8: return 0x7f;
case 9: return 0x6f;
case 0: return 0x3f;
}
}
โครงงานที่20
code
int Read_VR (void);
main()
{
int i,time;
TRISB = 0x00;
CMCON = 0x07;
while(1)
{
for(i=1;i<129;i=i*2)
{
PORTB = i;
time = Read_VR ()*2;
Vdelay_ms(time);
}
}
}
int Read_VR(void)
{
int i;
i = 0;
TRISA = 0xf0;
PORTA.F0 = 1;
Delay_ms(10);
TRISA = 0xF1;
while(PORTA.F0 == 1)
{
i++;
}
i = i/10;
return i ;
}
int Read_VR (void);
main()
{
int i,time;
TRISB = 0x00;
CMCON = 0x07;
while(1)
{
for(i=1;i<129;i=i*2)
{
PORTB = i;
time = Read_VR ()*2;
Vdelay_ms(time);
}
}
}
int Read_VR(void)
{
int i;
i = 0;
TRISA = 0xf0;
PORTA.F0 = 1;
Delay_ms(10);
TRISA = 0xF1;
while(PORTA.F0 == 1)
{
i++;
}
i = i/10;
return i ;
}
โครงงานที่17 ลูกเต๋าอิเล็กทรอนิกส์
code
void beep(void);
int display_led(int in);
main()
{
int i,j,time_n;
TRISB = 0x00;
CMCON = 0x07;
TRISA = 0xfd;
while(1)
{
time_n =120;
while(PORTA.F0==1)
{
time_n++;
if(time_n>240)
{
time_n=120;
}
}
j=1;
for(i=1;i<time_n;i++)
{
PORTB = display_led(j);
beep();
Delay_ms(10);
j++;
if(j>6)
{
j=1;
}
}
}
}
int display_led(int in)
{
switch(in)
{
case 1:return 0b0001000;
case 2:return 0b0010100;
case 3:return 0b0101010;
case 4:return 0b1100011;
case 5:return 0b1101011;
case 6:return 0b1110111;
}
}
void beep(void)
{
int i_b;
for(i_b=0;i_b<20;i_b++)
{
PORTA.F1=1;
Delay_us(300);
PORTA.F1=0;
Delay_us(300);
}
}
โครงงานที่16
code
int Read_T(void);
main()
{
TRISB = 0xF0;
CMCON = 0x07;
PORTB.F0=0;
while(1)
{
if(Read_T()<20)
{
PORTB.F0=1;
}
if(Read_T()>30)
{
PORTB.F0;
}
}
}
int Read_T(void)
{
int i;
i =0;
TRISA = 0xF0;
PORTA.F0 = 1;
Delay_ms(10);
TRISA = 0xF1;
while(PORTA.F
{
i++;
}
i = i/10;
return i ;
}
โครงงานที่14วงจรเครื่องนับจำนวณ
code
int conv7segment(int number);
main()
{
int i;
TRISB = 0x00;
CMCON = 0x07;
TRISA = 0xFF;
i = 0;
while(1)
{
while(PORTA.F0==0)
{
i++;
if(i>9)
{
i = 0;
}
while(PORTA.F0==0)
{
Delay_ms(10);
}
}
while(PORTA.F1==0)
{
i--;
if(i<0)
{
i = 9;
}
while(PORTA.F1==0)
{
Delay_ms(10);
}
}
PORTB = conv7segment(i);
}
}
int conv7segment(int number)
{
switch(number)
{
case 1: return 0x06;
case 2: return 0x5b;
case 3: return 0x4f;
case 4: return 0x66;
case 5: return 0x6d;
case 6: return 0x7d;
case 7: return 0x07;
case 8: return 0x7f;
case 9: return 0x6f;
case 0: return 0x3f;
}
}
โครงงานที่13 วงจรเครื่องตั้งเวลา
code
int conv7segment(int number);
main()
{
int minute,sec;
TRISB = 0x00;
TRISA = 0x00;
CMCON = 0x07;
PORTA.F0=0;
PORTA.F1=1;
for (minute=9;minute>0;minute--)
{
PORTB = conv7segment(minute);
for (sec=0;sec<=59;sec++)
{
PORTB.F7=1;
Delay_ms(100);
PORTB.F7=0;
Delay_ms(100);
}
}
PORTB = conv7segment(0);
PORTA.F0=1;
PORTA.F1=0;
}
int conv7segment(int number)
{
switch (number)
{
case 1: return 0x06;
case 2: return 0x5b;
case 3: return 0x4f;
case 4: return 0x66;
case 5: return 0x6d;
case 6: return 0x7d;
case 7: return 0x07;
case 8: return 0x7f;
case 9: return 0x6f;
case 0: return 0x3f;
}
}
โครงงานที่12 งานเครื่องทดสอบความไว
code
void alarm(void);
main()
{
TRISB = 0xF0;
while(1)
{
PORTB.F2=0;
PORTB.F3=0;
while(PORTB.F4==0)
{
while(PORTB.F6==1)
{
PORTB.F2=1;
alarm();
}
}
while(PORTB.F5==0)
{
while(PORTB.F6==1)
{
PORTB.F3=1;
alarm();
}
}
}
}
void alarm(void)
{
int i;
PORTB.F1=1;
for(i=0;i<500;i++)
{
PORTB.F0=1;
Delay_us(500);
PORTB.F0=0;
Delay_us(500);
}
PORTB.F1=0;
for(i=0;i<150;i++)
{
PORTB.F0=0;
Delay_us(1000);
}
}
โครงงานที่10 กล่องดนตรี
code
void alarm(void);
main()
{
TRISB = 0xF0;
while(1)
{
PORTB.F2=0;
PORTB.F3=0;
while(PORTB.F4==0)
{
while(PORTB.F6==1)
{
PORTB.F2=1;
alarm();
}
}
while(PORTB.F5==0)
{
while(PORTB.F6==1)
{
PORTB.F3=1;
alarm();
}
}
}
}
void alarm (void)
{
int i ;
PORTB.F1 = i;
for(i=0;i<500;i++)
{
PORTB.F0=1;
Delay_us(500);
PORTB.F0=0;
Delay_us(500);
}
PORTB.F1=0;
for(i=0;i<150;i++)
{
PORTB.F0=0;
Delay_us(1000);
}
}
void alarm(void);
main()
{
TRISB = 0xF0;
while(1)
{
PORTB.F2=0;
PORTB.F3=0;
while(PORTB.F4==0)
{
while(PORTB.F6==1)
{
PORTB.F2=1;
alarm();
}
}
while(PORTB.F5==0)
{
while(PORTB.F6==1)
{
PORTB.F3=1;
alarm();
}
}
}
}
void alarm (void)
{
int i ;
PORTB.F1 = i;
for(i=0;i<500;i++)
{
PORTB.F0=1;
Delay_us(500);
PORTB.F0=0;
Delay_us(500);
}
PORTB.F1=0;
for(i=0;i<150;i++)
{
PORTB.F0=0;
Delay_us(1000);
}
}
โครงงานที่8
code
void beep(void);
main()
{
int i;
TRISB= 0x00;
CMCON= 0x07;
TRISA= 0xfd;
while(1)
{
for(i=1;i<129;i=i*2)
{
PORTB = i;
while(PORTA.F0==0)
{
Delay_ms(3000);
}
beep();
Delay_ms(10);
}
}
}
void beep(void)
{
int i_b;
for(i_b=0;i_b<20;i_b++)
{
PORTA.F1=1;
Delay_ms(300);
PORTA.F1=0;
Delay_ms(300);
}
Subscribe to:
Posts (Atom)
สรุปงานที่ 5 Internet of Things (IoT)
Internet of Things (IoT) คืออะไร Internet of Things (IoT) คือ "อินเตอร์เน็ตในทุกสิ่ง" หมายถึง การที่อุปกรณ์ต่างๆ ส...
-
Digital Speedometer and Odometer Circuit using PIC Microcontroller EMBEDDED By Aswinth Raj Jul 27, 2017 24 Digital Speedometer and...
-
How to Save Data using EEPROM in PIC16F877A Microcontroller By Aswinth Raj Aug 10, 2017 2 Saving Data using...
-
Generating PWM using PIC Microcontroller with MPLAB and XC8 EMBEDDED By Aswinth Raj Mar 15, 2017 35 Generating PWM using PIC Micr...