PIC单片机论坛论坛展示区(非讨论区)(这个版块不能发新贴)『 单片机类精华贴子展示区 』 → CCSC LED3.c程序驱动MCD2demo LED数码管显示


  共有13946人关注过本帖树形打印

主题:CCSC LED3.c程序驱动MCD2demo LED数码管显示

帅哥哟,离线,有人找我吗?
lw7807
  1楼 个性首页 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:初中二年级 帖子:54 积分:1892 威望:0 精华:11 注册:2005-6-17 19:44:00
CCSC LED3.c程序驱动MCD2demo LED数码管显示  发帖心情 Post By:2005-6-20 22:11:00

/*=============================================================================
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()


支持(0中立(0反对(0回到顶部
帅哥哟,离线,有人找我吗?
lw7807
  2楼 个性首页 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:初中二年级 帖子:54 积分:1892 威望:0 精华:11 注册:2005-6-17 19:44:00
附上程序lst文件  发帖心情 Post By:2005-6-20 22:16:00

CCS PCM C Compiler, Version 3.187, 16465

Filename: D:\myPIC\ccsc_LED3.LST

ROM used: 129 (2%) Largest free fragment is 2048 RAM used: 25 (14%) at main() level 27 (15%) worst case Stack: 1 locations

* 0000: MOVLW 00 0001: MOVWF 0A 0002: GOTO 026 0003: NOP .................... /*============================================================================= .................... 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 .................... //////// Standard Header file for the PIC16F877A device //////////////// .................... #device PIC16F877A .................... #list .................... .................... #use delay(clock=4000000) // for 4Mhz crystal * 0011: MOVLW 34 0012: MOVWF 04 0013: MOVF 00,W 0014: BTFSC 03.2 0015: GOTO 025 0016: MOVLW 01 0017: MOVWF 78 0018: CLRF 77 0019: DECFSZ 77,F 001A: GOTO 019 001B: DECFSZ 78,F 001C: GOTO 018 001D: MOVLW 4A 001E: MOVWF 77 001F: DECFSZ 77,F 0020: GOTO 01F 0021: NOP 0022: NOP 0023: DECFSZ 00,F 0024: GOTO 016 0025: RETLW 00 .................... #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}; * 002F: MOVLW C0 0030: MOVWF 20 0031: MOVLW F9 0032: MOVWF 21 0033: MOVLW A4 0034: MOVWF 22 0035: MOVLW B0 0036: MOVWF 23 0037: MOVLW 99 0038: MOVWF 24 0039: MOVLW 92 003A: MOVWF 25 003B: MOVLW 82 003C: MOVWF 26 003D: MOVLW F8 003E: MOVWF 27 003F: MOVLW 80 0040: MOVWF 28 0041: MOVLW 90 0042: MOVWF 29 0043: MOVLW FF 0044: MOVWF 2A .................... //LED 1 2 3 4 5 6 .................... int8 BYT[] = { 0xfd, 0xfe, 0xf7, 0xfb, 0xdf, 0xef}; 0045: MOVLW FD 0046: MOVWF 2B 0047: MOVLW FE 0048: MOVWF 2C 0049: MOVLW F7 004A: MOVWF 2D 004B: MOVLW FB 004C: MOVWF 2E 004D: MOVLW DF 004E: MOVWF 2F 004F: MOVLW EF 0050: MOVWF 30 .................... .................... /////////////////////////////////////////////////////////////////////////////// .................... // .................... void led_display_num(int8 pos, int8 num) .................... { .................... output_c(SEG[num]); * 0004: MOVLW 20 0005: ADDWF 34,W 0006: MOVWF 04 0007: MOVF 00,W 0008: MOVWF 35 0009: MOVWF 07 .................... output_a(BYT[pos]); 000A: MOVLW 2B 000B: ADDWF 33,W 000C: MOVWF 04 000D: MOVF 00,W 000E: MOVWF 35 000F: MOVWF 05 .................... }//end led_show_num() 0010: RETLW 00 .................... .................... /*===========================================================================*/ .................... void main(void) .................... { * 0026: CLRF 04 0027: MOVLW 1F 0028: ANDWF 03,F 0029: MOVLW 06 002A: BSF 03.5 002B: MOVWF 1F 002C: MOVLW 07 002D: BCF 03.5 002E: MOVWF 1F .................... int8 i; .................... int8 j; .................... .................... set_tris_c(0x00); * 0051: MOVLW 00 0052: BSF 03.5 0053: MOVWF 07 .................... set_tris_a(0x00); 0054: MOVWF 05 .................... while(1){ .................... for(i=0; i<10; i++) // LED1 display 0 to off 0055: BCF 03.5 0056: CLRF 31 0057: MOVF 31,W 0058: SUBLW 09 0059: BTFSS 03.0 005A: GOTO 068 .................... { .................... led_display_num(0, i); 005B: CLRF 33 005C: MOVF 31,W 005D: MOVWF 34 005E: CALL 004 .................... delay_ms(500); 005F: MOVLW 02 0060: MOVWF 33 0061: MOVLW FA 0062: MOVWF 34 0063: CALL 011 0064: DECFSZ 33,F 0065: GOTO 061 .................... } 0066: INCF 31,F 0067: GOTO 057 .................... .................... for(j=0; j<100; j++) // LED1 to 6 display 0 to 5 0068: CLRF 32 0069: MOVF 32,W 006A: SUBLW 63 006B: BTFSS 03.0 006C: GOTO 07E .................... { .................... for(i=0; i<6; i++) 006D: CLRF 31 006E: MOVF 31,W 006F: SUBLW 05 0070: BTFSS 03.0 0071: GOTO 07C .................... { .................... led_display_num(i, i); 0072: MOVF 31,W 0073: MOVWF 33 0074: MOVF 31,W 0075: MOVWF 34 0076: CALL 004 .................... delay_ms(15); 0077: MOVLW 0F 0078: MOVWF 34 0079: CALL 011 .................... }//end for(i) 007A: INCF 31,F 007B: GOTO 06E .................... }//end for(j) 007C: INCF 32,F 007D: GOTO 069 .................... }//end while(1) 007E: BSF 03.5 007F: GOTO 055 .................... }//end main() .................... 0080: SLEEP

Configuration Fuses: Word 1: 3F79 XT NOWDT NOPUT NODEBUG NOPROTECT BROWNOUT NOLVP NOCPD NOWRT


支持(1中立(1反对(0回到顶部
Google 全部 本站