void led() { uchar i; beep(); P2=0xfe; for(i=0;i<4;i++) { if(i) P2=_crol_(P2,2); delay(1000); } P2=0xfd; for(i=0;i<4;i++) { if(i) P2=_crol_(P2,2); delay(1000); } i=3; while(i--) { P2=0x00; delay(1000); P2=0xff; delay(1000); } }
void main() { temp1=0xfe; temp2=0x7f; //间隔300ms先奇数亮再偶数亮,循环三次 for(m=0;m<3;m++) { P1=0xAA; delay1(); P1=0x55; delay1(); } //一个灯上下循环三次 for(m=0;m<3;m++) { for(n=0;n<8;n++) { P1=temp1; temp1= _crol_(temp1,1); delay1(); } for(n=0;n<8;n++) { P1=temp2; temp2= _cror_(temp2,1); delay1(); } } //两个分别从两边往中间流动三次,再从中间往两边流动三次 for(m=0;m<3;m++) { for(n=0;n<4;n++) { P1=temp1&temp2; temp1= _crol_(temp1,1); temp2= _cror_(temp2,1); delay1(); } for(n=0;n<4;n++) { P1=temp1&temp2; temp1= _crol_(temp1,1); temp2= _cror_(temp2,1); delay1(); } } //8个全部闪烁3次 for(m=0;m<3;m++) { P1=0x00; delay1(); P1=0xff; delay1(); } //关闭发光管 P1=0xff; delay1(); }
// sends the nbits least significant bits in big-endian order, e.g. sendConfigBits(0xfe,3) sends 110 from 1111 1110 void sendConfigBits(unsigned char b,unsigned char nbits){ unsigned char i=nbits; // send this many b=_crol_(b,8-nbits); // rotate to get msb of data to send in msb of b. if nbits=8 doesn't change b, if nbits=7, rotates left by 1 while(nbits--){ b=_crol_(b,1); // get the next bit in lsb if(b&1!=0){ bitIn=1; }else{ bitIn=0; } clockOnce(); } }
void main (void) { while(1) { aa=0xfe; // left flashing part for (i=0; i<7; i++) { P1=aa; beep=0; aa=_crol_(aa, 1); // left LIB function delayms(100); P1=0xff; beep=1; delayms(200); } aa=0x7f; // right flashing part for (i=0; i<7; i++) { P1=aa; beep=0; aa=_cror_(aa, 1); delayms(100); P1=0xff; beep=1; delayms(200); } } }
/*------------------------------------------------ 主程序 ------------------------------------------------*/ main() { LED=0XFE; Init_Timer0(); while(1) { if(i==500) { if(KeyValue) { LED=_cror_(LED,1); i=0; } else { LED=_crol_(LED,1); i=0; } } } }
void decode_key() { uchar k; P1 = 0x0F;l9=1;//低位置○,准备查询按键 k = P1; //取得当前P1口的状态 if(k != 0x0F) {//如果有变化则表示有键按下 k = 0xef; do{//循环扫描每一行 P1 = k; if(k != P1) { switch(P1) { //第一行 case 0x77:{keykeep=KEY_OK;break;} case 0xb7:{keykeep=KEY_CE;break;} case 0xd7:{keykeep=KEY_NUM0;break;} case 0xe7:{keykeep=KEY_DOT;break;} //第二行 case 0x7b:{keykeep=KEY_DN;break;} case 0xbb:{keykeep=KEY_NUM3;break;} case 0xdb:{keykeep=KEY_NUM2;break;} case 0xeb:{keykeep=KEY_NUM1;break;} //第三行 case 0x7d:{keykeep=KEY_UP;break;} case 0xbd:{keykeep=KEY_NUM6;break;} case 0xdd:{keykeep=KEY_NUM5;break;} case 0xed:{keykeep=KEY_NUM4;break;} //第四行 case 0x7e:{keykeep=KEY_TAB;break;} case 0xbe:{keykeep=KEY_NUM9;break;} case 0xde:{keykeep=KEY_NUM8;break;} case 0xee:{keykeep=KEY_NUM7;break;} default: break; } } k = _crol_(k,1);//移位,进入下一行扫描 }while(k !=0xef);//超过范围退出 } P1 = 0xff;l9=0; //第五列如下 k = P1; if(k != 0xff) { switch(P1) { //第五行 case 0xf7:{keykeep=KEY_BTN4; break;} case 0xfb:{keykeep=KEY_BTN3;break;} case 0xfd:{keykeep=KEY_BTN2; break;} case 0xfe:{keykeep=KEY_BTN1;break;} default: break; } } P1 = 0x0f;l9=0; }
void led_flash(void) { uint8_t led = 0xFE; while(1) { LED = led; sys_delay_1s(1); led = _crol_(led , 1); } }
void proc_key(unsigned char key_v) { if((key_v & 0x01) == 0) { P2 = _cror_(P2,1); } else if((key_v & 0x02) == 0) { P2 = _crol_(P2, 1); } }
//sends byte dat in big endian order out the DAC bit and clock outputs. // must leave clock low at end so that clock can be taken high *after* sync is taken high after all bytes clocked in void sendDACByte(unsigned char b){ unsigned char i=8; while(i--){ dacClock=1; b=_crol_(b,1); // rotate left to get msb to lsb if(b&1){ dacBitIn=1; }else{ dacBitIn=0; } dacClock=0; // clk edge low while data stable } }
// sends the byte out the 'spi' interface to the cochlea in big-endian order (msb first) // - replaces assembly routine to use bit defines for clock and bitIn and C code void sendConfigByte(unsigned char b){ unsigned char i=8; while(i--){ // goes till i==0 // rotate left to get msb, test bit to set bitin, then toggle clock high/low b=_crol_(b,1); if(b&1!=0){ bitIn=1; }else{ bitIn=0; } clockOnce(); } }
void write_spi_con(unsigned char A1, unsigned char value) { static unsigned char t; t = 0; t = _crol_(A1,1); while (command != NU); cs_con = 0; CSCON = 0; command = WR1; SPI0DAT = t; A2 = value; while (command != NU); CSCON = 1; }
void segscan() { uchar i; uint t=200; beep(); while(t--) { i=5; P1=0xef; while(i--) { P0=tableca[i]; if(i-4!=0) P1=_crol_(P1,1); delay(5); P0=0xff; } } }
void main() { int temp; int led_count; while(1) { P0=0xfe; //P0^0输出低电平 temp = P0; for(led_count=7;led_count>=0;led_count--) { delay_on(255); // temp = temp<<1; // temp += 1; // P0 = temp; temp = _crol_(temp, 1); // _crol_将temp循环左移1位,无需像上面再加1 P0 = temp; } } }
void main() { EA=1; ET1=1; TMOD=0x10; TH1=(65535-50000)>>8; TL1=(65535-50000)%256; TR1=1; temp=0xfe; while(1) { if(num==2) { num=0; P1=temp; temp= _crol_(temp,1); } } }
unsigned char read_spi_con(unsigned char A1) { static unsigned char t; t = 0; t = _crol_(A1,1); t |= 0x40; command = RD; cs_con = 0; CSCON = 0; SPI0DAT = t; while (command != NU); command = RD; SPI0DAT = 0x00; //A3 = SPI0DAT; while (command != NU); A3 = SPI0DAT; CSCON = 1; return (A3); }
/******************************************************************** * 名称 : Main() * 功能 : 实现灯的闪烁 * 输入 : 无 * 输出 : 无 * 说明 :也可以使用例1的的方法来关闭数码管 ***********************************************************************/ void Main(void) { uchar i; P2 = 0x00; while(1) { P0 = 0x7f; //P0.7亮亮 for(i=0; i<7; i++) //移位7次 { P0 = _cror_(P0, 1); //_crol_()这个函数在intrins.h中定义了,用于循环右移 Delay(15); } P0 = 0xfe; for(i=0; i<7; i++) { P0 = _crol_(P0, 1); //用于循环左移 Delay(15); } } }
void flow(int t,unsigned char way) { unsigned char temp,i; if(way==1) { temp=0xfe; for(i=0;i<8;i++) { P2=temp; temp=_crol_(temp,1); delay(t); } } if(way==2) { temp=0x7f; for(i=0;i<8;i++) { P2=temp; temp=_cror_(temp,1); delay(t); } } }
void main() { init(); m=count=0; duan=1; P0=0x3f; duan=0; wei=1; P0=0xfe; wei=0; sum=433; flag=sec=shi=ge=0; while(1) { if(num1==10&&m<7) { num1=0; if(sum>398) { sum--; } else { flag=1; } sec=sum/100; shi=(sum%100)/10; ge=sum%10; //注意数码管显示函数放的位置 } //display(sec,shi,ge); if(num0==50&&m<7) { num0=0; if(flag!=1) { P1=_crol_(0xfe,count); count++; count=count%8; } else { m++; } } if(m>6) { P1=0xff; display1(); } else { if(m%2==1) P1=0x00; else P1=0xff; display(sec,shi,ge); } // display(count,shi,ge); } }