PIC单片机论坛论坛展示区(非讨论区)(这个版块不能发新贴)『 单片机类精华贴子展示区 』 → CCSC timer.c程序使用MCD2demo 用PIC16F877A片内Timer1定时


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

主题:CCSC timer.c程序使用MCD2demo 用PIC16F877A片内Timer1定时

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


加好友 发短信
等级:初中二年级 帖子:54 积分:1892 威望:0 精华:11 注册:2005-6-17 19:44:00
CCSC timer.c程序使用MCD2demo 用PIC16F877A片内Timer1定时  发帖心情 Post By:2005-6-23 21:03:00

/*=============================================================================
使用PIC16F877A片内Timer1定时,运行程序:
        程序开始    -> LED0亮,
        每0.5秒钟   -> LED7交替亮灭,
        循环10次后  -> Timer1中断关闭,LED6亮,LED7保持当前状态。
=============================================================================*/
///////////////////////////////////////////////////////////////////////////////
// MPLAB IDE V7.11 + CCS C3.18
// Use 16F877A internal timer1 for MCD2-demo
//
// by LW7807@163.com
// 2005/06/22
///////////////////////////////////////////////////////////////////////////////
#include <16F877A.h>                            // PIC16F877 header file
#use delay(clock=4000000)                       // for 4Mhz crystal
#fuses XT, NOWDT, NOPROTECT, NOLVP              // for debug mode


#define TIMER1_500MS            (0xFFFF - 62500 + 1)
#define DO_THIS_TIMES           10

#define LED7_IO                 PIN_C7
#define LED6_IO                 PIN_C6
#define LED0_IO                 PIN_C0
#define LED_ON                  1
#define LED_OFF                 0


int1    led7_status             = LED_OFF;
int8    cnt                     = 0;

///////////////////////////////////////////////////////////////////////////////
//
#int_TIMER1
void timer1_isr(void)
{
        led7_status = ~led7_status;

        ++ cnt;
        if(cnt >= 2*DO_THIS_TIMES)
                {
                disable_interrupts(INT_TIMER1);
                output_bit(LED6_IO, LED_ON);
                }
}//end timer1_isr()

/*===========================================================================*/
void main(void)
{
        // begin program
        output_bit(LED0_IO, LED_ON);

        // setup timer1 for 0.5s interrupt
        setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
        set_timer1(TIMER1_500MS);
        enable_interrupts(INT_TIMER1);
        enable_interrupts(GLOBAL);

        // show led7 status
        while(1){
                output_bit(LED7_IO, led7_status);
                }
}//end main()


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


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

CCS PCM C Compiler, Version 3.187, 16465

Filename: D:\myPIC\ccsc_timer.LST

ROM used: 115 (1%) Largest free fragment is 2048 RAM used: 16 (9%) at main() level 16 (9%) worst case Stack: 1 worst case (0 in main + 1 for interrupts)

* 0000: MOVLW 00 0001: MOVWF 0A 0002: GOTO 049 0003: NOP 0004: MOVWF 7F 0005: SWAPF 03,W 0006: CLRF 03 0007: MOVWF 21 0008: MOVF 0A,W 0009: MOVWF 20 000A: CLRF 0A 000B: MOVF 04,W 000C: MOVWF 22 000D: MOVF 77,W 000E: MOVWF 23 000F: MOVF 78,W 0010: MOVWF 24 0011: MOVF 79,W 0012: MOVWF 25 0013: MOVF 7A,W 0014: MOVWF 26 0015: MOVF 7B,W 0016: MOVWF 27 0017: BCF 03.7 0018: BCF 03.5 0019: MOVLW 8C 001A: MOVWF 04 001B: BTFSS 00.0 001C: GOTO 01F 001D: BTFSC 0C.0 001E: GOTO 032 001F: MOVF 22,W 0020: MOVWF 04 0021: MOVF 23,W 0022: MOVWF 77 0023: MOVF 24,W 0024: MOVWF 78 0025: MOVF 25,W 0026: MOVWF 79 0027: MOVF 26,W 0028: MOVWF 7A 0029: MOVF 27,W 002A: MOVWF 7B 002B: MOVF 20,W 002C: MOVWF 0A 002D: SWAPF 21,W 002E: MOVWF 03 002F: SWAPF 7F,F 0030: SWAPF 7F,W 0031: RETFIE 0032: BCF 0A.3 0033: BCF 0A.4 0034: GOTO 035 .................... /*============================================================================= .................... 使用PIC16F877A片内Timer1定时,运行程序: .................... 程序开始 -> LED0亮, .................... 每0.5秒钟 -> LED7交替亮灭, .................... 循环10次后 -> Timer1中断关闭,LED6亮,LED7保持当前状态。 .................... =============================================================================*/ .................... /////////////////////////////////////////////////////////////////////////////// .................... // MPLAB IDE V7.11 + CCS C3.18 .................... // Use 16F877A internal timer1 for MCD2-demo .................... // .................... // by LW7807@163.com .................... // 2005/06/22 .................... /////////////////////////////////////////////////////////////////////////////// .................... #include <16F877A.h> // PIC16F877 header file .................... //////// Standard Header file for the PIC16F877A device //////////////// .................... #device PIC16F877A .................... #list .................... .................... #use delay(clock=4000000) // for 4Mhz crystal .................... #fuses XT, NOWDT, NOPROTECT, NOLVP // for debug mode .................... .................... .................... #define TIMER1_500MS (0xFFFF - 62500 + 1) .................... #define DO_THIS_TIMES 10 .................... .................... #define LED7_IO PIN_C7 .................... #define LED6_IO PIN_C6 .................... #define LED0_IO PIN_C0 .................... #define LED_ON 1 .................... #define LED_OFF 0 .................... .................... .................... int1 led7_status = LED_OFF; * 0052: BCF 28.0 .................... int8 cnt = 0; 0053: CLRF 29 .................... .................... /////////////////////////////////////////////////////////////////////////////// .................... // .................... #int_TIMER1 .................... void timer1_isr(void) .................... { .................... led7_status = ~led7_status; * 0035: MOVLW 01 0036: XORWF 28,F .................... .................... ++ cnt; 0037: INCF 29,F .................... if(cnt >= 2*DO_THIS_TIMES) .................... { 0038: MOVF 29,W 0039: SUBLW 13 003A: BTFSC 03.0 003B: GOTO 045 .................... disable_interrupts(INT_TIMER1); 003C: BSF 03.5 003D: BCF 0C.0 .................... output_bit(LED6_IO, LED_ON); 003E: BCF 03.5 003F: BSF 07.6 0040: BCF 2A.6 0041: MOVF 2A,W 0042: BSF 03.5 0043: MOVWF 07 0044: BCF 03.5 * 0054: MOVLW FF 0055: MOVWF 2A .................... } .................... }//end timer1_isr() .................... .................... /*===========================================================================*/ * 0045: BCF 0C.0 0046: BCF 0A.3 0047: BCF 0A.4 0048: GOTO 01F .................... void main(void) .................... { 0049: CLRF 04 004A: MOVLW 1F 004B: ANDWF 03,F 004C: MOVLW 06 004D: BSF 03.5 004E: MOVWF 1F 004F: MOVLW 07 0050: BCF 03.5 0051: MOVWF 1F .................... // begin program .................... output_bit(LED0_IO, LED_ON); * 0056: BSF 07.0 0057: BCF 2A.0 0058: MOVF 2A,W 0059: BSF 03.5 005A: MOVWF 07 .................... .................... // setup timer1 for 0.5s interrupt .................... setup_timer_1(T1_INTERNAL | T1_DIV_BY_8); 005B: MOVLW B5 005C: BCF 03.5 005D: MOVWF 10 .................... set_timer1(TIMER1_500MS); 005E: MOVLW 0B 005F: MOVWF 0F 0060: MOVLW DC 0061: MOVWF 0E .................... enable_interrupts(INT_TIMER1); 0062: BSF 03.5 0063: BSF 0C.0 .................... enable_interrupts(GLOBAL); 0064: MOVLW C0 0065: BCF 03.5 0066: IORWF 0B,F .................... .................... // show led7 status .................... while(1){ .................... output_bit(LED7_IO, led7_status); 0067: BTFSC 28.0 0068: GOTO 06B 0069: BCF 07.7 006A: GOTO 06C 006B: BSF 07.7 006C: BCF 2A.7 006D: MOVF 2A,W 006E: BSF 03.5 006F: MOVWF 07 .................... } 0070: BCF 03.5 0071: GOTO 067 .................... }//end main() .................... 0072: SLEEP

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


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