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


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

主题:CCSC intEE.c程序使用MCD2demo 访问PIC16F877A片内EEPROM

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


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

/*=============================================================================
访问PIC16F877A片内EEPROM,运行程序:
        Begin Test    -> LED0亮,
        EEPROM Test OK-> LED7亮,
        Write&Read OK -> LED0/2/4/6亮。
=============================================================================*/
///////////////////////////////////////////////////////////////////////////////
// MPLAB IDE V7.11 + CCS C3.18
// Access 16F877A internal EEPROM 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 EEPROM_SIZE       256

////////////////////////////////////////////////////////////// eeprom_test()
//
int8 eeprom_test(void)
{
        int16 i;

        // write 0x55 test
        for(i=0; i<EEPROM_SIZE; ++i)
                {
                write_eeprom(i, 0x55);
                }
        for(i=0; i<EEPROM_SIZE; ++i)
                {
                if(0x55 != read_eeprom(i)) return 0;
                }

        // write 0xaa test
        for(i=0; i<EEPROM_SIZE; ++i)
                {
                write_eeprom(i, 0xaa);
                }
        for(i=0; i<EEPROM_SIZE; ++i)
                {
                if(0xaa != read_eeprom(i)) return 0;
                }

        // write 0
        for(i=0; i<EEPROM_SIZE; ++i)
                {
                write_eeprom(i, 0x00);
                }
        return 0xff;
}//end eeprom_test()

/*===========================================================================*/
void main(void)
{
        // begin test
        output_high(PIN_C0);

        // test internal eeprom
        if(0 != eeprom_test())
                {
                output_high(PIN_C7);
                delay_ms(1000);
                }

        // write 24c02
        write_eeprom(0, 0x55);

        // read 24c02
        output_c(read_eeprom(0));
}//end main()


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


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

CCS PCM C Compiler, Version 3.187, 16465

Filename: D:\myPIC\ccsc_intEE.LST

ROM used: 293 (4%) Largest free fragment is 2048 RAM used: 7 (4%) at main() level 8 (5%) worst case Stack: 1 locations

* 0000: MOVLW 00 0001: MOVWF 0A 0002: GOTO 0D6 0003: NOP .................... /*============================================================================= .................... 访问PIC16F877A片内EEPROM,运行程序: .................... Begin Test -> LED0亮, .................... EEPROM Test OK-> LED7亮, .................... Write&Read OK -> LED0/2/4/6亮。 .................... =============================================================================*/ .................... /////////////////////////////////////////////////////////////////////////////// .................... // MPLAB IDE V7.11 + CCS C3.18 .................... // Access 16F877A internal EEPROM 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 * 00BF: MOVLW 22 00C0: MOVWF 04 00C1: MOVF 00,W 00C2: BTFSC 03.2 00C3: GOTO 0D3 00C4: MOVLW 01 00C5: MOVWF 78 00C6: CLRF 77 00C7: DECFSZ 77,F 00C8: GOTO 0C7 00C9: DECFSZ 78,F 00CA: GOTO 0C6 00CB: MOVLW 4A 00CC: MOVWF 77 00CD: DECFSZ 77,F 00CE: GOTO 0CD 00CF: NOP 00D0: NOP 00D1: DECFSZ 00,F 00D2: GOTO 0C4 00D3: BCF 0A.3 00D4: BCF 0A.4 00D5: GOTO 0F6 (RETURN) .................... #fuses XT, NOWDT, NOPROTECT, NOLVP // for debug mode .................... .................... #define EEPROM_SIZE 256 .................... .................... ////////////////////////////////////////////////////////////// eeprom_test() .................... // .................... int8 eeprom_test(void) .................... { .................... int16 i; .................... .................... // write 0x55 test .................... for(i=0; i<EEPROM_SIZE; ++i) * 0004: CLRF 22 0005: CLRF 21 0006: MOVF 22,W 0007: SUBLW 00 0008: BTFSS 03.0 0009: GOTO 02D .................... { .................... write_eeprom(i, 0x55); 000A: MOVF 22,W 000B: BSF 03.6 000C: MOVWF 0E 000D: BCF 03.6 000E: MOVF 21,W 000F: BSF 03.6 0010: MOVWF 0D 0011: MOVLW 55 0012: MOVWF 0C 0013: BSF 03.5 0014: BCF 0C.7 0015: BSF 0C.2 0016: BCF 03.5 0017: BCF 03.6 0018: MOVF 0B,W 0019: MOVWF 77 001A: BCF 0B.7 001B: BSF 03.5 001C: BSF 03.6 001D: MOVLW 55 001E: MOVWF 0D 001F: MOVLW AA 0020: MOVWF 0D 0021: BSF 0C.1 0022: BTFSC 0C.1 0023: GOTO 022 0024: BCF 0C.2 0025: MOVF 77,W 0026: BCF 03.5 0027: BCF 03.6 0028: IORWF 0B,F .................... } 0029: INCF 21,F 002A: BTFSC 03.2 002B: INCF 22,F 002C: GOTO 006 .................... for(i=0; i<EEPROM_SIZE; ++i) 002D: CLRF 22 002E: CLRF 21 002F: MOVF 22,W 0030: SUBLW 00 0031: BTFSS 03.0 0032: GOTO 04A .................... { .................... if(0x55 != read_eeprom(i)) return 0; 0033: MOVF 22,W 0034: BSF 03.6 0035: MOVWF 0E 0036: BCF 03.6 0037: MOVF 21,W 0038: BSF 03.6 0039: MOVWF 0D 003A: BSF 03.5 003B: BCF 0C.7 003C: BSF 0C.0 003D: BCF 03.5 003E: MOVF 0C,W 003F: SUBLW 55 0040: BTFSC 03.2 0041: GOTO 045 0042: MOVLW 00 0043: MOVWF 78 0044: GOTO 0BB .................... } 0045: BCF 03.6 0046: INCF 21,F 0047: BTFSC 03.2 0048: INCF 22,F 0049: GOTO 02F .................... .................... // write 0xaa test .................... for(i=0; i<EEPROM_SIZE; ++i) 004A: CLRF 22 004B: CLRF 21 004C: MOVF 22,W 004D: SUBLW 00 004E: BTFSS 03.0 004F: GOTO 073 .................... { .................... write_eeprom(i, 0xaa); 0050: MOVF 22,W 0051: BSF 03.6 0052: MOVWF 0E 0053: BCF 03.6 0054: MOVF 21,W 0055: BSF 03.6 0056: MOVWF 0D 0057: MOVLW AA 0058: MOVWF 0C 0059: BSF 03.5 005A: BCF 0C.7 005B: BSF 0C.2 005C: BCF 03.5 005D: BCF 03.6 005E: MOVF 0B,W 005F: MOVWF 77 0060: BCF 0B.7 0061: BSF 03.5 0062: BSF 03.6 0063: MOVLW 55 0064: MOVWF 0D 0065: MOVLW AA 0066: MOVWF 0D 0067: BSF 0C.1 0068: BTFSC 0C.1 0069: GOTO 068 006A: BCF 0C.2 006B: MOVF 77,W 006C: BCF 03.5 006D: BCF 03.6 006E: IORWF 0B,F .................... } 006F: INCF 21,F 0070: BTFSC 03.2 0071: INCF 22,F 0072: GOTO 04C .................... for(i=0; i<EEPROM_SIZE; ++i) 0073: CLRF 22 0074: CLRF 21 0075: MOVF 22,W 0076: SUBLW 00 0077: BTFSS 03.0 0078: GOTO 090 .................... { .................... if(0xaa != read_eeprom(i)) return 0; 0079: MOVF 22,W 007A: BSF 03.6 007B: MOVWF 0E 007C: BCF 03.6 007D: MOVF 21,W 007E: BSF 03.6 007F: MOVWF 0D 0080: BSF 03.5 0081: BCF 0C.7 0082: BSF 0C.0 0083: BCF 03.5 0084: MOVF 0C,W 0085: SUBLW AA 0086: BTFSC 03.2 0087: GOTO 08B 0088: MOVLW 00 0089: MOVWF 78 008A: GOTO 0BB .................... } 008B: BCF 03.6 008C: INCF 21,F 008D: BTFSC 03.2 008E: INCF 22,F 008F: GOTO 075 .................... .................... // write 0 .................... for(i=0; i<EEPROM_SIZE; ++i) 0090: CLRF 22 0091: CLRF 21 0092: MOVF 22,W 0093: SUBLW 00 0094: BTFSS 03.0 0095: GOTO 0B8 .................... { .................... write_eeprom(i, 0x00); 0096: MOVF 22,W 0097: BSF 03.6 0098: MOVWF 0E 0099: BCF 03.6 009A: MOVF 21,W 009B: BSF 03.6 009C: MOVWF 0D 009D: CLRF 0C 009E: BSF 03.5 009F: BCF 0C.7 00A0: BSF 0C.2 00A1: BCF 03.5 00A2: BCF 03.6 00A3: MOVF 0B,W 00A4: MOVWF 77 00A5: BCF 0B.7 00A6: BSF 03.5 00A7: BSF 03.6 00A8: MOVLW 55 00A9: MOVWF 0D 00AA: MOVLW AA 00AB: MOVWF 0D 00AC: BSF 0C.1 00AD: BTFSC 0C.1 00AE: GOTO 0AD 00AF: BCF 0C.2 00B0: MOVF 77,W 00B1: BCF 03.5 00B2: BCF 03.6 00B3: IORWF 0B,F .................... } 00B4: INCF 21,F 00B5: BTFSC 03.2 00B6: INCF 22,F 00B7: GOTO 092 .................... return 0xff; 00B8: MOVLW FF 00B9: MOVWF 78 00BA: BSF 03.6 .................... }//end eeprom_test() 00BB: BCF 03.6 00BC: BCF 0A.3 00BD: BCF 0A.4 00BE: GOTO 0E8 (RETURN) .................... .................... /*===========================================================================*/ .................... void main(void) .................... { * 00D6: CLRF 04 00D7: MOVLW 1F 00D8: ANDWF 03,F 00D9: MOVLW 06 00DA: BSF 03.5 00DB: MOVWF 1F 00DC: MOVLW 07 00DD: BCF 03.5 00DE: MOVWF 1F .................... // begin test .................... output_high(PIN_C0); 00DF: MOVLW FF 00E0: MOVWF 20 00E1: BCF 20.0 00E2: MOVF 20,W 00E3: BSF 03.5 00E4: MOVWF 07 00E5: BCF 03.5 00E6: BSF 07.0 .................... .................... // test internal eeprom .................... if(0 != eeprom_test()) .................... { 00E7: GOTO 004 00E8: MOVF 78,F 00E9: BTFSC 03.2 00EA: GOTO 0F8 .................... output_high(PIN_C7); 00EB: BCF 20.7 00EC: MOVF 20,W 00ED: BSF 03.5 00EE: MOVWF 07 00EF: BCF 03.5 00F0: BSF 07.7 .................... delay_ms(1000); 00F1: MOVLW 04 00F2: MOVWF 21 00F3: MOVLW FA 00F4: MOVWF 22 00F5: GOTO 0BF 00F6: DECFSZ 21,F 00F7: GOTO 0F3 .................... } .................... .................... // write 24c02 .................... write_eeprom(0, 0x55); 00F8: BSF 03.6 00F9: CLRF 0E 00FA: CLRF 0D 00FB: MOVLW 55 00FC: MOVWF 0C 00FD: BSF 03.5 00FE: BCF 0C.7 00FF: BSF 0C.2 0100: BCF 03.5 0101: BCF 03.6 0102: MOVF 0B,W 0103: MOVWF 77 0104: BCF 0B.7 0105: BSF 03.5 0106: BSF 03.6 0107: MOVLW 55 0108: MOVWF 0D 0109: MOVLW AA 010A: MOVWF 0D 010B: BSF 0C.1 010C: BTFSC 0C.1 010D: GOTO 10C 010E: BCF 0C.2 010F: MOVF 77,W 0110: BCF 03.5 0111: BCF 03.6 0112: IORWF 0B,F .................... .................... // read 24c02 .................... output_c(read_eeprom(0)); 0113: BSF 03.6 0114: CLRF 0E 0115: CLRF 0D 0116: BSF 03.5 0117: BCF 0C.7 0118: BSF 0C.0 0119: BCF 03.5 011A: MOVF 0C,W 011B: BCF 03.6 011C: MOVWF 21 011D: MOVLW 00 011E: MOVWF 20 011F: BSF 03.5 0120: MOVWF 07 0121: BCF 03.5 0122: MOVF 21,W 0123: MOVWF 07 .................... }//end main() .................... 0124: SLEEP

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


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


加好友 发短信
等级:小学一年级 帖子:1 积分:223 威望:0 精华:0 注册:2011-9-16 13:41:00
[原创]回复EEPORM程序  发帖心情 Post By:2011-9-30 10:34:00

这BBS很多程序不仅乱 还烂


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