void main()
{
unsigned int analog;
TRISA=0xFF;
TRISB=0;
TRISC=0;
PORTB=0;
PORTC=0;
while(1)
{
analog=Adc_Read(3);
if(analog>0&&analog<=64)PORTB=0x80;
else if(analog>64&&analog<=2*64)PORTB=0xC0;
else if(analog>2*64&&analog<=3*64)PORTB=0xE0;
else if(analog>3*64&&analog<=4*64)PORTB=0xF0;
else if(analog>4*64&&analog<=5*64)PORTB=0xF8;
else if(analog>5*64&&analog<=6*64)PORTB=0xFC;
else if(analog>6*64&&analog<=7*64)PORTB=0xFE;
else if(analog>7*64&&analog<=8*64)PORTB=0xFF;
else if(analog>8*64&&analog<=9*64)
{
PORTB=0xFF;
PORTC=0x80;
}
else if(analog>9*64&&analog<=10*64)
{
PORTB=0xFF;
PORTC=0xC0;
}
else if(analog>10*64&&analog<=11*64)
{
PORTB=0xFF;
PORTC=0xE0;
}
else if(analog>11*64&&analog<=12*64)
{
PORTB=0xFF;
PORTC=0xF0;
}
else if(analog>12*64&&analog<=13*64)
{
PORTB=0xFF;
PORTC=0xF8;
}
else if(analog>13*64&&analog<=14*64)
{
PORTB=0xFF;
PORTC=0xFC;
}
else if(analog>14*64&&analog<=15*64)
{
PORTB=0xFF;
PORTC=0xFE;
}
else if(analog>15*64)
{
PORTB=0xFF;
PORTC=0xFF;
}
else
{
PORTB=0;
PORTC=0;
}
}
}
วันจันทร์ที่ 7 มกราคม พ.ศ. 2562
T19
void main()
{
unsigned long int voltage;
unsigned char v1,v2,v3;
TRISA=0xFF;
TRISC=0;
Lcd_Init(&PORTC);
Lcd_Cmd(LCD_CURSOR_OFF);
Lcd_Cmd(LCD_CLEAR);
while(1)
{
Lcd_Cmd(LCD_CLEAR);
voltage=Adc_Read(3);
voltage=voltage*489/1000;
v1=voltage/100;
v2=(voltage%100)/10;
v3=voltage%10;
Lcd_Chr(1,1,v1+48);
Lcd_Chr(1,2,'.');
Lcd_Chr(1,3,v2+48);
Lcd_Chr(1,4,v3+48);
Lcd_Chr(1,5,' ');
Lcd_Chr(1,6,'v');
delay_ms(500);
}
}
{
unsigned long int voltage;
unsigned char v1,v2,v3;
TRISA=0xFF;
TRISC=0;
Lcd_Init(&PORTC);
Lcd_Cmd(LCD_CURSOR_OFF);
Lcd_Cmd(LCD_CLEAR);
while(1)
{
Lcd_Cmd(LCD_CLEAR);
voltage=Adc_Read(3);
voltage=voltage*489/1000;
v1=voltage/100;
v2=(voltage%100)/10;
v3=voltage%10;
Lcd_Chr(1,1,v1+48);
Lcd_Chr(1,2,'.');
Lcd_Chr(1,3,v2+48);
Lcd_Chr(1,4,v3+48);
Lcd_Chr(1,5,' ');
Lcd_Chr(1,6,'v');
delay_ms(500);
}
}
T18
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
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;
}
T14
#define r1 PORTB.F0
#define r2 PORTB.F1
#define r3 PORTB.F2
#define r4 PORTB.F3
#define r5 PORTB.F4
#define r6 PORTB.F5
#define r7 PORTB.F6
#define r8 PORTB.F7
#define c1 PORTC.F0
#define c2 PORTC.F1
#define c3 PORTC.F2
#define c4 PORTC.F3
#define c5 PORTC.F4
#define c6 PORTC.F5
#define c7 PORTC.F6
#define c8 PORTC.F7
void delay_reset()
{
delay_ms(5);
PORTC=0;PORTB=0xFF;
}
void main()
{
TRISB=0;
TRISC=0;
PORTC=0;PORTB=0xFF;
while(1)
{
c4=1;r4=0;r5=0;delay_reset();
c5=1;r4=0;r5=0;delay_reset();
delay_ms(100);
c3=1;PORTB=0xC3;delay_reset();
c4=1;r3=0;r6=0;delay_reset();
c5=1;r3=0;r6=0;delay_reset();
c6=1;PORTB=0xC3;delay_reset();
delay_ms(100);
c2=1;PORTB=0x81;delay_reset();
c3=1;r2=0;r7=0;delay_reset();
c4=1;r2=0;r7=0;delay_reset();
c5=1;r2=0;r7=0;delay_reset();
c6=1;r2=0;r7=0;delay_reset();
c7=1;PORTB=0x81;delay_reset();
delay_ms(100);
c1=1;PORTB=0;delay_reset();
c2=1;r1=0;r8=0;delay_reset();
c3=1;r1=0;r8=0;delay_reset();
c4=1;r1=0;r8=0;delay_reset();
c5=1;r1=0;r8=0;delay_reset();
c6=1;r1=0;r8=0;delay_reset();
c7=1;r1=0;r8=0;delay_reset();
c8=1;PORTB=0;delay_reset();
delay_ms(100);
}
}
T13
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
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
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
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;
}
}
T8
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
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
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);
}
}
T5
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
#define digit1 PORTB.F6
#define digit2 PORTB.F7
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;
digit1=0;digit2=1;
PORTC=segment[i];
delay_ms(50);
digit1=1;digit2=0;
PORTC=segment[j];
delay_ms(50);
}
}
T3
#define digit1 PORTE.F0
#define digit2 PORTE.F1
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)
{
digit1=0;digit2=1;
PORTC=segment[i1];
PORTD=segment[i3];
PORTB=segment[i5];
delay_ms(15);
digit1=1;digit2=0;
PORTC=segment[i2];
PORTD=segment[i4];
PORTB=segment[i6];
delay_ms(15);
}
}
T2
#define digit1 PORTB.F5
#define digit2 PORTB.F6
#define digit3 PORTB.F7
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)
{
digit1=0;digit2=1;digit3=1;
PORTC=segment[i];
delay_ms(25);
digit1=1;digit2=0;digit3=1;
PORTC=~0x3F;
delay_ms(25);
digit1=1;digit2=1;digit3=0;
PORTC=segment[j];
delay_ms(25);
}
}
T1
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;
}
}
สมัครสมาชิก:
บทความ (Atom)