วันจันทร์ที่ 14 มกราคม พ.ศ. 2562

T18




#line 1 "C:/Users/bunthit/Desktop/TEST 1/T18.c"
void main()
{
 unsigned char segment[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
 unsigned char step[]={0x01,0x02,0x04,0x08};
 unsigned char i,j;
 TRISB=0;
 TRISC=0;
 PORTB=segment[0];
 while(1)
 {
 for(i=0;i<4;i++)
 {
 PORTC=step[i];
 delay_ms(500);
 }
 j++;
 PORTB=segment[j];
 if(j>8)
 {
 while(1)PORTC=0x00;
 }
 }
}

T17





#line 1 "C:/Users/bunthit/Desktop/TEST 1/T17.c"
void main()
{
 unsigned char rcw,rccw;
 unsigned char step_cw[]={0x01,0x02,0x04,0x08};
 unsigned char step_ccw[]={0x04,0x02,0x01,0x08};
 unsigned char keypad[]={0,1,2,3,0,
 4,5,6,0,
 7,8,9,0,
 0,0,0,0};
 unsigned char i,m,kp;
 TRISB=0;
 TRISC=0;
 TRISD=0xFF;
 Lcd_Init(&PORTB);
 Keypad_Init(&PORTD);
 Lcd_Cmd(LCD_CURSOR_OFF);
 Return:Lcd_Cmd(LCD_CLEAR);
 Lcd_Out(1,1,"Rotate CW?");
 while(!Keypad_Read());
 kp=Keypad_Read();
 rcw=keypad[kp];
 Lcd_Chr(2,1,keypad[kp]+48);
 while(Keypad_Read());
 while(Keypad_Read()!=15);
 while(Keypad_Read());
 Lcd_Cmd(LCD_CLEAR);
 Lcd_Out(1,1,"Rotate CCW?");
 while(!Keypad_Read());
 kp=Keypad_Read();
 rccw=keypad[kp];
 Lcd_Chr(2,1,keypad[kp]+48);
 while(Keypad_Read());
 while(Keypad_Read()!=15);
 while(Keypad_Read());
 Lcd_Cmd(LCD_CLEAR);
 Lcd_Out(1,1,"Rotating...");
 for(i=0;i<rcw;i++)
 {
 while(m<4)
 {
 PORTC=step_cw[m];
 delay_ms(500);
 m++;
 }
 m=0;
 }
 for(i=0;i<rccw;i++)
 {
 while(m<4)
 {
 PORTC=step_ccw[m];
 delay_ms(500);
 m++;
 }
 m=0;
 }
 goto Return;
}

T16



#line 1 "C:/Users/bunthit/Desktop/TEST 1/T16.c"
void main()
{
 unsigned int analog;
 TRISA=0xFF;
 TRISC=0;
 T2CON=0x02;
 CCP1CON=0x0C;
 PR2=0xFF;
 T2CON.TMR2ON=1;
 while(1)
 {
 analog=Adc_Read(3);
 analog=analog/4;
 CCPR1L=analog;
 }
}

T15




#line 1 "C:/Users/bunthit/Desktop/TEST 1/T15.c"
void main()
{
 TRISC=0;
 T2CON=0x00;
 PR2=0x18;
 CCPR1L=0x0C;
 CCP1CON=0x2C;
 T2CON.TMR2ON=1;
}

T14


#line 1 "C:/Users/bunthit/Desktop/TEST 1/T14.c"
#line 18 "C:/Users/bunthit/Desktop/TEST 1/T14.c"
void delay_reset()
{
 delay_ms(5);
 PORTC=0;PORTB=0xFF;
}

void main()
{
 TRISB=0;
 TRISC=0;
 PORTC=0;PORTB=0xFF;
 while(1)
 {
  PORTC.F3 =1; PORTB.F3 =0; PORTB.F4 =0;delay_reset();
  PORTC.F4 =1; PORTB.F3 =0; PORTB.F4 =0;delay_reset();

 delay_ms(100);

  PORTC.F2 =1;PORTB=0xC3;delay_reset();
  PORTC.F3 =1; PORTB.F2 =0; PORTB.F5 =0;delay_reset();
  PORTC.F4 =1; PORTB.F2 =0; PORTB.F5 =0;delay_reset();
  PORTC.F5 =1;PORTB=0xC3;delay_reset();

 delay_ms(100);

  PORTC.F1 =1;PORTB=0x81;delay_reset();
  PORTC.F2 =1; PORTB.F1 =0; PORTB.F6 =0;delay_reset();
  PORTC.F3 =1; PORTB.F1 =0; PORTB.F6 =0;delay_reset();
  PORTC.F4 =1; PORTB.F1 =0; PORTB.F6 =0;delay_reset();
  PORTC.F5 =1; PORTB.F1 =0; PORTB.F6 =0;delay_reset();
  PORTC.F6 =1;PORTB=0x81;delay_reset();

 delay_ms(100);

  PORTC.F0 =1;PORTB=0;delay_reset();
  PORTC.F1 =1; PORTB.F0 =0; PORTB.F7 =0;delay_reset();
  PORTC.F2 =1; PORTB.F0 =0; PORTB.F7 =0;delay_reset();
  PORTC.F3 =1; PORTB.F0 =0; PORTB.F7 =0;delay_reset();
  PORTC.F4 =1; PORTB.F0 =0; PORTB.F7 =0;delay_reset();
  PORTC.F5 =1; PORTB.F0 =0; PORTB.F7 =0;delay_reset();
  PORTC.F6 =1; PORTB.F0 =0; PORTB.F7 =0;delay_reset();
  PORTC.F7 =1;PORTB=0;delay_reset();

 delay_ms(100);
 }
}

T13




#line 1 "C:/Users/bunthit/Desktop/TEST 1/T13.c"
void main()
{
 unsigned char num[4];
 unsigned char input[4];
 unsigned char a,b;
 unsigned char keypad[]={0,1,2,3,0,
 4,5,6,0,
 7,8,9,0,
 0,0,0,0};
 unsigned int kp,i,j;
 TRISC=0;
 TRISD=0xFF;
 Lcd_Init(&PORTC);
 Keypad_Init(&PORTD);
 Lcd_Cmd(LCD_CURSOR_OFF);
 Lcd_Cmd(LCD_CLEAR);
 Lcd_Out(1,1,"Enter 4 numbers");
 for(i=0;i<4;i++)
 {
 while(!Keypad_Read());
 kp=Keypad_Read();
 num[i]=keypad[kp];
 Lcd_Chr(2,i+1,keypad[kp]+48);
 while(Keypad_Read());
 }
 while(Keypad_Read()!=15);
 Return:Lcd_Cmd(LCD_CLEAR);
 Lcd_Out(1,1,"What are 4 numbers?");
 while(Keypad_Read());
 for(i=0;i<4;i++)
 {
 while(!Keypad_Read());
 kp=Keypad_Read();
 input[i]=keypad[kp];
 Lcd_Chr(2,i+1,keypad[kp]+48);
 while(Keypad_Read());
 }
 while(Keypad_Read()!=15);
 Lcd_Cmd(LCD_CLEAR);
 while(Keypad_Read());
 for(i=0;i<4;i++)
 {
 if(input[i]==num[i])
 {
 a++;
 continue;
 }
 for(j=0;j<4;j++)
 {
 if(input[i]==num[j])b++;
 }
 }
 Lcd_Chr(1,1,a+48);
 Lcd_Chr(1,2,'A');
 Lcd_Chr(1,3,b+48);
 Lcd_Chr(1,4,'B');
 if(a==4)Lcd_Out(2,1,"Correct");
 else
 {
 Lcd_Out(2,1,"Wrong!");
 a=0;b=0;
 while(Keypad_Read()!=15);
 goto Return;
 }
}

T12



void main()
{
     unsigned char num;
     unsigned char input;
     unsigned char keypad[]={0,1,2,3,0,
                               4,5,6,0,
                               7,8,9,0,
                               0,0,0,0};
     unsigned int kp,i;
     TRISC=0;
     TRISD=0xFF;
     Lcd_Init(&PORTC);
     Keypad_Init(&PORTD);
     Lcd_Cmd(LCD_CURSOR_OFF);
     Lcd_Cmd(LCD_CLEAR);
     Lcd_Out(1,1,"Enter number");
     for(i=0;i<2;i++)
     {
            while(!Keypad_Read());
            kp=Keypad_Read();
            num=num*10*i+keypad[kp];
            Lcd_Chr(2,i+1,keypad[kp]+48);
            while(Keypad_Read());
     }
     while(Keypad_Read()!=15);
     Return:Lcd_Cmd(LCD_CLEAR);
     Lcd_Out(1,1,"What is number?");
     while(Keypad_Read());
     for(i=0;i<2;i++)
     {
            while(!Keypad_Read());
            kp=Keypad_Read();
            input=input*10*i+keypad[kp];
            Lcd_Chr(2,i+1,keypad[kp]+48);
            while(Keypad_Read());
     }
     while(Keypad_Read()!=15);
     Lcd_Cmd(LCD_CLEAR);
     while(Keypad_Read());
     if(num>input)
     {
            Lcd_Out(1,1,"More than!");
            while(Keypad_Read()!=15);
            goto Return;
     }
     else if(num<input)
     {
            Lcd_Out(1,1,"Less than!");
            while(Keypad_Read()!=15);
            goto Return;
     }
     else
     {
            Lcd_Out(1,1,"Correct");
     }
}




T11




#line 1 "C:/Users/bunthit/Desktop/TEST 1/T11.c"
void timer0_setup()
{
 T0CON.TMR0ON=0;
 INTCON.TMR0IF=0;
 TMR0H=0xC2;
 TMR0L=0xF7;
 T0CON.TMR0ON=1;
}

void main()
{
 TRISC=0;
 TRISD=0xFF;
 T0CON=0x05;
 Lcd_Init(&PORTC);
 Keypad_Init(&PORTD);
 Lcd_Cmd(LCD_CURSOR_OFF);
 Lcd_Cmd(LCD_CLEAR);
 Lcd_Chr(1,1,'3');
 timer0_setup();
 while(INTCON.TMR0IF==0)
 {
 if(Keypad_Read()==3)
 {
 Lcd_Chr(1,1,' ');
 break;
 }
 }
 Lcd_Chr(2,5,'6');
 timer0_setup();
 while(INTCON.TMR0IF==0)
 {
 if(Keypad_Read()==7)
 {
 Lcd_Chr(2,5,' ');
 break;
 }
 }
 Lcd_Chr(1,9,'8');
 timer0_setup();
 while(INTCON.TMR0IF==0)
 {
 if(Keypad_Read()==10)
 {
 Lcd_Chr(1,9,' ');
 break;
 }
 }
 Lcd_Chr(2,16,'0');
 timer0_setup();
 while(INTCON.TMR0IF==0)
 {
 if(Keypad_Read()==14)
 {
 Lcd_Chr(2,16,' ');
 break;
 }
 }
 Lcd_Chr(2,1,'7');
 timer0_setup();
 while(INTCON.TMR0IF==0)
 {
 if(Keypad_Read()==9)
 {
 Lcd_Chr(2,1,' ');
 break;
 }
 }
 Lcd_Chr(1,12,'4');
 timer0_setup();
 while(INTCON.TMR0IF==0)
 {
 if(Keypad_Read()==5)
 {
 Lcd_Chr(1,12,' ');
 break;
 }
 }
 Lcd_Chr(2,9,'1');
 timer0_setup();
 while(INTCON.TMR0IF==0)
 {
 if(Keypad_Read()==1)
 {
 Lcd_Chr(2,9,' ');
 break;
 }
 }
 Lcd_Chr(1,16,'5');
 timer0_setup();
 while(INTCON.TMR0IF==0)
 {
 if(Keypad_Read()==6)
 {
 Lcd_Chr(1,16,' ');
 break;
 }
 }
 Lcd_Chr(1,5,'9');
 timer0_setup();
 while(INTCON.TMR0IF==0)
 {
 if(Keypad_Read()==11)
 {
 Lcd_Chr(1,5,' ');
 break;
 }
 }
 Lcd_Chr(2,12,'2');
 timer0_setup();
 while(INTCON.TMR0IF==0)
 {
 if(Keypad_Read()==2)
 {
 Lcd_Chr(1,12,' ');
 break;
 }
 }
}

T10




#line 1 "C:/Users/bunthit/Desktop/TEST 1/T10.c"
void main()
{
 unsigned char Dec,d1,d2,d3;
 unsigned char Bin[8];
 unsigned char keypad[]={0,1,2,3,0,
 4,5,6,0,
 7,8,9,0,
 0,0,0,0};
 unsigned int kp,i;
 TRISC=0;
 TRISD=0xFF;
 Lcd_Init(&PORTC);
 Keypad_Init(&PORTD);
 Lcd_Cmd(LCD_CURSOR_OFF);
 Return:Lcd_Cmd(LCD_CLEAR);
 Lcd_Out(1,1,"Dec>Bin Bin>Dec");
 Lcd_Out(2,1,"   1       2   ");
 while(Keypad_Read()!=1&&Keypad_Read()!=2);
 if(Keypad_Read()==1)goto DectoBin;
 if(Keypad_Read()==2)goto BintoDec;
 DectoBin:while(Keypad_Read());
 Lcd_Cmd(LCD_CLEAR);
 Lcd_Out(1,1,"Enter Dec");
 for(i=0;i<2;i++)
 {
 while(!Keypad_Read());
 kp=Keypad_Read();
 Dec=Dec*10*i+keypad[kp];
 Lcd_Chr(2,i+1,keypad[kp]+48);
 while(Keypad_Read());
 }
 Bin[0]=Dec%2;
 Bin[1]=(Dec/2)%2;
 Bin[2]=(Dec/4)%2;
 Bin[3]=(Dec/8)%2;
 Bin[4]=(Dec/16)%2;
 Bin[5]=(Dec/32)%2;
 Bin[6]=(Dec/64)%2;
 Bin[7]=(Dec/128)%2;
 while(Keypad_Read()!=15);
 Lcd_Cmd(LCD_CLEAR);
 Lcd_Out(1,1,"Bin");
 for(i=0;i<8;i++)
 {
 Lcd_Chr(2,i+1,Bin[7-i]+48);
 }
 while(Keypad_Read());
 while(Keypad_Read()!=15);
 goto Return;
 BintoDec:while(Keypad_Read());
 Lcd_Cmd(LCD_CLEAR);
 Lcd_Out(1,1,"Enter Bin");
 for(i=0;i<8;i++)
 {
 while(Keypad_Read()!=1&&Keypad_Read()!=14);
 kp=Keypad_Read();
 Bin[7-i]=keypad[kp];
 Lcd_Chr(2,i+1,Bin[7-i]+48);
 while(Keypad_Read());
 }
 Dec=Bin[0];
 Dec=Dec+Bin[1]*2;
 Dec=Dec+Bin[2]*4;
 Dec=Dec+Bin[3]*8;
 Dec=Dec+Bin[4]*16;
 Dec=Dec+Bin[5]*32;
 Dec=Dec+Bin[6]*64;
 Dec=Dec+Bin[7]*128;
 d1=Dec/100;
 d2=(Dec%100)/10;
 d3=Dec%10;
 while(Keypad_Read()!=15);
 Lcd_Cmd(LCD_CLEAR);
 Lcd_Out(1,1,"Dec");
 Lcd_Chr(2,1,d1+48);
 Lcd_Chr(2,2,d2+48);
 Lcd_Chr(2,3,d3+48);
 while(Keypad_Read());
 while(Keypad_Read()!=15);
 goto Return;
}

T9



#line 1 "C:/Users/bunthit/Desktop/TEST 1/T9.c"
void main()
{
 unsigned int equ[4];
 unsigned char keypad[]={0,7,8,9,0,
 4,5,6,0,
 1,2,3,0,
 0,0,0,0};
 unsigned char kp,i;
 unsigned char r[4];
 TRISC=0;
 TRISD=0xFF;
 Lcd_Init(&PORTC);
 Keypad_Init(&PORTD);
 Lcd_Cmd(LCD_CURSOR_OFF);
 RETURN:while(Keypad_Read());
 Lcd_Cmd(LCD_CLEAR);
 Lcd_Chr(1,1,'0');
 for(i=0;i<2;i++)
 {
 while(!Keypad_Read());
 if(Keypad_Read()==16)
 {
 equ[1]=10;
 goto STEP2;
 }
 if(Keypad_Read()==8)
 {
 equ[1]=11;
 goto STEP2;
 }
 kp=Keypad_Read();
 Lcd_Chr(1,i+1,keypad[kp]+48);
 equ[0]=equ[0]*10*i+keypad[kp];
 while(Keypad_Read());
 }
 while(Keypad_Read()!=8&&Keypad_Read()!=16);
 if(Keypad_Read()==16)equ[1]=10;
 if(Keypad_Read()==8)equ[1]=11;
 STEP2:while(Keypad_Read());
 Lcd_Cmd(LCD_CLEAR);
 Lcd_Chr(1,1,'0');
 for(i=0;i<2;i++)
 {
 while(!Keypad_Read());
 if(Keypad_Read()==15)goto STEP3;
 kp=Keypad_Read();
 Lcd_Chr(1,i+1,keypad[kp]+48);
 equ[2]=equ[2]*10*i+keypad[kp];
 while(Keypad_Read());
 }
 while(Keypad_Read()!=15);
 STEP3:if(equ[1]==10)equ[3]=equ[0]+equ[2];
 if(equ[1]==11)equ[3]=equ[0]*equ[2];
 r[3]=equ[3]/1000;
 r[2]=(equ[3]%1000)/100;
 r[1]=(equ[3]%100)/10;
 r[0]=equ[3]%10;
 Lcd_Cmd(LCD_CLEAR);
 Lcd_Chr(1,1,'=');
 for(i=0;i<4;i++)
 {
 Lcd_Chr(1,i+2,r[3-i]+48);
 }
 while(Keypad_Read()!=13);
 goto RETURN;
}

T8




#line 1 "C:/Users/bunthit/Desktop/TEST 1/T8.c"
void main()
{
 unsigned char password[]={1,2,3,4};
 unsigned char input[4];
 unsigned char keypad[]={0,1,2,3,0,
 4,5,6,0,
 7,8,9,0,
 0,0,0,0};
 unsigned int kp,i;
 TRISC=0;
 TRISD=0xFF;
 Lcd_Init(&PORTC);
 Keypad_Init(&PORTD);
 Lcd_Cmd(LCD_CURSOR_OFF);
 RETURN:Lcd_Cmd(LCD_CLEAR);
 Lcd_Out(1,1,"ENTER PASSWORD");
 for(i=0;i<4;i++)
 {
 while(!Keypad_Read());
 kp=Keypad_Read();
 input[i]=keypad[kp];
 Lcd_Chr(2,i+1,input[i]+48);
 while(Keypad_Read());
 }
 while(Keypad_Read()!=15);
 if(input[0]==password[0]&&input[1]==password[1]&&input[2]==password[2]&&input[3]==password[3])
 {
 Lcd_Cmd(LCD_CLEAR);
 Lcd_Out(1,1,"CORRECT PASSWORD");
 }
 else
 {
 Lcd_Cmd(LCD_CLEAR);
 Lcd_Out(1,1,"WRONG PASSWORD");
 delay_ms(1000);
 goto RETURN;
 }
}

T7



#line 1 "C:/Users/bunthit/Desktop/TEST 1/T7.c"
void main()
{
 unsigned char clock[4];
 unsigned char sec;
 TRISC=0;
 Lcd_Init(&PORTC);
 Lcd_Cmd(LCD_CURSOR_OFF);
 Lcd_Cmd(LCD_CLEAR);
 T0CON=0x05;
 TMR0H=0xC2;
 TMR0L=0xF7;
 INTCON.TMR0IF=0;
 T0CON.TMR0ON=1;
 while(1)
 {
 Lcd_Chr(1,6,clock[0]+48);
 Lcd_Chr(1,7,clock[1]+48);
 Lcd_Chr(1,8,':');
 Lcd_Chr(1,9,clock[2]+48);
 Lcd_Chr(1,10,clock[3]+48);
 while(!INTCON.TMR0IF);
 T0CON.TMR0ON=0;
 sec++;
 if(sec>59)
 {
 sec=0;
 clock[3]++;
 }
 if(clock[3]>9)
 {
 clock[3]=0;
 clock[2]++;
 }
 if(clock[2]>5)
 {
 clock[2]=0;
 clock[1]++;
 }
 if(clock[1]>9)
 {
 clock[1]=0;
 clock[0]++;
 }
 if(clock[0]==2&&clock[1]>3)
 {
 clock[0]=0;
 clock[1]=0;
 }
 TMR0H=0xC2;
 TMR0L=0xF7;
 INTCON.TMR0IF=0;
 T0CON.TMR0ON=1;
 Lcd_Cmd(LCD_CLEAR);
 }
}

T6




#line 1 "C:/Users/bunthit/Desktop/TEST 1/T6.c"
void main()
{
 TRISB=0xFF;
 TRISC=0;
 Lcd_Init(&PORTC);
 Lcd_Cmd(LCD_CURSOR_OFF);
 Lcd_Cmd(LCD_CLEAR);
 Lcd_Out(1,2,"                SMART LEARNING");
 Lcd_Out(2,1,"                ADVANCE PIC BY C");
 while(1)
 {
 RETURN:if(PORTB.F0==0)
 {
 Lcd_Cmd(LCD_SHIFT_RIGHT);
 while(PORTB.F0==0);
 }
 if(PORTB.F1==0)
 {
 Lcd_Cmd(LCD_SHIFT_LEFT);
 while(PORTB.F1==0);
 }
 if(PORTB.F2==0)
 {
 while(1)
 {
 Lcd_Cmd(LCD_SHIFT_RIGHT);
 delay_ms(100);
 if(PORTB.F0==0||PORTB.F1==0)goto RETURN;
 }
 }
 }
}

T5



#line 1 "C:/Users/bunthit/Desktop/TEST 1/T5.c"
unsigned char segment[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char i1,i2,i3,i4,i5,i6;

void interrupt()
{
 i6++;
 if(i6>9)
 {
 i6=0;
 i5++;
 }
 if(i5>9)
 {
 i5=0;
 i4++;
 }
 if(i4>9)
 {
 i4=0;
 i3++;
 }
 if(i3>9)
 {
 i3=0;
 i2++;
 }
 if(i2>9)
 {
 i2=0;
 i1++;
 }
 if(i1>9)i1=0;
 INTCON.INT0IF=0;
}

void main()
{
 TRISB=0xFF;
 TRISC=0;
 TRISD=0;
 INTCON.INT0IE=1;
 INTCON.INT0IF=0;
 INTCON2.INTEDG0=0;
 INTCON.GIE=1;
 while(1)
 {
 PORTD=0xDF;
 PORTC=segment[i1];
 delay_ms(10);
 PORTD=0xEF;
 PORTC=segment[i2];
 delay_ms(10);
 PORTD=0xF7;
 PORTC=segment[i3];
 delay_ms(10);
 PORTD=0xFB;
 PORTC=segment[i4];
 delay_ms(10);
 PORTD=0xFD;
 PORTC=segment[i5];
 delay_ms(10);
 PORTD=0xFE;
 PORTC=segment[i6];
 delay_ms(10);
 }
}

T4


#line 1 "C:/Users/bunthit/Desktop/TEST 1/T4.c"



unsigned char segment[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
int i=6,j=0;

void interrupt()
{
 j--;
 if(j<0)
 {
 j=9;
 i--;
 }
 if(i==0&&j==0)
 {
 T0CON.TMR0ON=0;
 PORTB.F5=1;
 }
 TMR0H=0xC2;
 TMR0L=0xF7;
 INTCON.TMR0IF=0;
}

void main()
{
 TRISB=0x01;
 TRISC=0;
 PORTB.F5=0;
 T0CON=0x05;
 TMR0H=0xC2;
 TMR0L=0xF7;
 INTCON.TMR0IE=1;
 INTCON.TMR0IF=0;
 INTCON.GIE=1;
 while(1)
 {
 if(PORTB.F0==0)T0CON.TMR0ON=1;
  PORTB.F6 =0; PORTB.F7 =1;
 PORTC=segment[i];
 delay_ms(50);
  PORTB.F6 =1; PORTB.F7 =0;
 PORTC=segment[j];
 delay_ms(50);
 }
}

T3



 #line 1 "C:/Users/bunthit/Desktop/TEST 1/T3.c"



unsigned char segment[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char i1,i2,i3,i4,i5,i6;

void interrupt()
{
 i6++;
 if(i6>9)
 {
 i6=0;
 i5++;
 }
 if(i5>9)
 {
 i5=0;
 i4++;
 }
 if(i4>9)
 {
 i4=0;
 i3++;
 }
 if(i3>5)
 {
 i3=0;
 i2++;
 }
 if(i2>9)
 {
 i2=0;
 i1++;
 }
 if(i1>5)i1=0;
 TMR3H=0xD8;
 TMR3L=0xF0;
 PIR2.TMR3IF=0;
}

void main()
{
 TRISB=0;
 TRISC=0;
 TRISD=0;
 TRISE=0;
 T3CON=0x80;
 TMR3H=0xD8;
 TMR3L=0xF0;
 PIE2.TMR3IE=1;
 PIR2.TMR3IF=0;
 INTCON.PEIE=1;
 INTCON.GIE=1;
 T3CON.TMR3ON=1;
 while(1)
 {
  PORTE.F0 =0; PORTE.F1 =1;
 PORTC=segment[i1];
 PORTD=segment[i3];
 PORTB=segment[i5];
 delay_ms(25);
  PORTE.F0 =1; PORTE.F1 =0;
 PORTC=segment[i2];
 PORTD=segment[i4];
 PORTB=segment[i6];
 delay_ms(25);
 }
}

T2


  โค้ดภาษาซี

#line 1 "C:/Users/bunthit/Desktop/TEST 1/T2.c"




unsigned char segment[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char i,j;

void interrupt()
{
 if(INTCON.INT0IF==1)
 {
 i++;
 if(i>9)i=0;
 INTCON.INT0IF=0;
 }
 if(INTCON3.INT1IF==1)
 {
 j++;
 if(j>9)j=0;
 INTCON3.INT1IF=0;
 }
}

void main()
{
 TRISB=0x03;
 TRISC=0;
 INTCON.INT0IE=1;
 INTCON.INT0IF=0;
 INTCON2.INTEDG0=0;
 INTCON3.INT1IE=1;
 INTCON3.INT1IF=0;
 INTCON2.INTEDG1=0;
 INTCON.GIE=1;
 while(1)
 {
  PORTB.F5 =0; PORTB.F6 =1; PORTB.F7 =1;
 PORTC=segment[i];
 delay_ms(25);
  PORTB.F5 =1; PORTB.F6 =0; PORTB.F7 =1;
 PORTC=~0x3F;
 delay_ms(25);
  PORTB.F5 =1; PORTB.F6 =1; PORTB.F7 =0;
 PORTC=segment[j];
 delay_ms(25);
 }

}

T1

\
                     
                                                                     
    โค้ดภาษาซี


#line 1 "C:/Users/bunthit/Desktop/TEST 1/T1.c"
 void main()
{
 unsigned char dice[]={0x08,0x22,0x2A,0x55,0x5D,0x77};
 unsigned char i;
 TRISC=0;
 TRISB=0x01;
 PORTC=0;
 while(1)
 {
 if(PORTB.F0==0)
 {
 PORTC=dice[i];
 delay_ms(3000);
 PORTC=0;
 }
 i++;
 if(i>5)i=0;
 }
}