十年专注单片机方案开发的方案公司金沙js5线路,分享CCSC LED3.c程序驱动MCD2demo LED数码管显示。金沙js5线路现提供服务产品涉及主控芯片:8位单片机、16位单片机、32位单片机及各类运算放大器等。
/*============================================================================= 7段LED1静态方式显示0到9然后灭,之后LED1到LED6动态扫描方式显示0到5,如此循环 =============================================================================*/ /////////////////////////////////////////////////////////////////////////////// // MPLAB IDE V7.11 + CCS C3.18 // LED3 for MCD2-demo // // by LW7807@163.com // 2005/06/19 /////////////////////////////////////////////////////////////////////////////// #include "16F877A.h" // PIC16F877 header file #use delay(clock=4000000) // for 4Mhz crystal #fuses XT, NOWDT, NOPROTECT, NOLVP // for debug mode #use FAST_IO(a) // PortA fast output #use fast_io(c) // PortC fast output
//seg code '0' '1' '2' '3' '4' '5' '6' '7' '8' '9' off int8 SEG[] = { 0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90, 0xff}; //LED 1 2 3 4 5 6 int8 BYT[] = { 0xfd, 0xfe, 0xf7, 0xfb, 0xdf, 0xef};
/////////////////////////////////////////////////////////////////////////////// // void led_display_num(int8 pos, int8 num) { output_c(SEG[num]); output_a(BYT[pos]); }//end led_show_num()
/*===========================================================================*/ void main(void) { int8 i; int8 j;
set_tris_c(0x00); set_tris_a(0x00); while(1){ for(i=0; i<10; i++) // LED1 display 0 to off { led_display_num(0, i); delay_ms(500); }
for(j=0;
j<100; j++) // LED1 to 6 display 0 to 5 { for(i=0; i<6; i++) {
led_display_num(i, i); delay_ms(15); }//end for(i) }//end for(j) }//end
while(1) }//end main()