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


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

主题:CCSC LCD.c程序驱动MCD2demo LCD显示

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


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

/*=============================================================================
LCD第一行显示"01234567890:;<=>?"; 第二行显示"PIC16F877A CCSC "
=============================================================================*/
///////////////////////////////////////////////////////////////////////////////
// MPLAB IDE V7.11 + CCS C3.18
// LCD for MCD2-demo
//
// by LW7807@163.com
// 2005/06/20
///////////////////////////////////////////////////////////////////////////////
#include "16F877A.h"                            // PIC16F877 header file
#use delay(clock=4000000)                       // for 4Mhz crystal
#fuses XT, NOWDT, NOPROTECT, NOLVP              // for debug mode

#define PORT_A                  0               // define for function output()
#define PORT_B                  1
#define PORT_C                  2
#define PORT_D                  3
#define PORT_E                  4


#define NCHAR_PER_LINE          16              // max char numbers per line

#define LCD_RS                  PIN_A1
#define LCD_RW                  PIN_A2
#define LCD_E                   PIN_A3
#define LCD_DAT                 PORT_C

/////////////////////////////////////////////////////////// output()
//lcd data bus output
void output(int8 port, int8 dat)
{
        switch(port)
                {
                case PORT_A: output_a(dat);      break;
                case PORT_B: output_b(dat);      break;
                case PORT_C: output_c(dat);      break;
                case PORT_D: output_d(dat);      break;
                case PORT_E: output_e(dat);      break;
                default :       //??? port maybe error!
                        break;
                }
}//end output()

/////////////////////////////////////////////////////////// lcd_write_cmd()
//
void lcd_write_cmd(int8 cmd)
{
        delay_us(400);
        output_low(LCD_RS);
        output_low(LCD_RW);
        output(LCD_DAT, cmd);

        output_high(LCD_E);
        delay_us(400);
        output_low(LCD_E);
}//end lcd_write_cmd()

/////////////////////////////////////////////////////////// lcd_write_dat()
//
void lcd_write_dat(int8 dat)
{
        delay_us(400);
        output_high(LCD_RS);
        output_low(LCD_RW);
        output(LCD_DAT, dat);

        output_high(LCD_E);
        delay_us(400);
        output_low(LCD_E);
}//end lcd_write_dat()

/////////////////////////////////////////////////////////// lcd_init()
//
void lcd_init(void)
{
        output_low(LCD_E);              // Let LCD E line low

        lcd_write_cmd(0x38);           // LCD 16x2, 5x7, 8bits data
        delay_ms(15);
        lcd_write_cmd(0x01);            // Clear LCD display
        delay_ms(10);
        lcd_write_cmd(0x0f);            // Open display & current
        delay_ms(10);
        lcd_write_cmd(0x06);            // Window fixed
        delay_ms(10);
}//end lcd_init()

/////////////////////////////////////////////////////////// lcd_display_char()
//
void lcd_display_char(int8 line, int8 pos, int8 ch)
{
        int8 tmp;

        line = (line==0) ? 0 : 1;
        pos  = (pos >NCHAR_PER_LINE) ? NCHAR_PER_LINE : pos;

        tmp = 0x80 + 0x40*line + pos;
        lcd_write_cmd(tmp);
        lcd_write_dat(ch);
}//end lcd_display_char()

/////////////////////////////////////////////////////////// lcd_display_str()
//
void lcd_display_str(int8 line, char str[])
{
        int8 i;

        for(i=0; i<NCHAR_PER_LINE; i++)
         {
                lcd_display_char(line, i, ' ');
                }
        for(i=0; i<NCHAR_PER_LINE; i++)
                {
                if(str == '\0') break;
                lcd_display_char(line, i, str);
                }
}//end lcd_display_str()


/*===========================================================================*/
void main(void)
{
        char LINE2[] = { "PIC16F877A CCSC LCD.C" };
        int8 i;

        lcd_init();

        for(i=0; i<NCHAR_PER_LINE; i++)
                {
                lcd_display_char(0, i, '0'+i);
                }
        //lcd_display_str(1, "PIC16F877A CCSC LCD.C")   //CCSC can't compiler
        lcd_display_str(1, LINE2);
}//end main()


/*===========================================================================*/
void main(void)
{
        char LINE2[] = { "PIC16F877A CCSC LCD.C" };
        int8 i;

        lcd_init();

        for(i=0; i<NCHAR_PER_LINE; i++)
                {
                lcd_display_char(0, i, '0'+i);
                }
        //lcd_display_str(1, "PIC16F877A CCSC LCD.C")   //CCSC can't compiler
        lcd_display_str(1, LINE2);
}//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:04:00

CCS PCM C Compiler, Version 3.187, 16465

Filename: ccsc_LCD.LST

ROM used: 323 (4%) Largest free fragment is 2048 RAM used: 30 (17%) at main() level 40 (23%) worst case Stack: 4 locations

* 0000: MOVLW 00 0001: MOVWF 0A 0002: GOTO 0F8 0003: NOP .................... /*============================================================================= .................... LCD第一行显示"01234567890:;<=>??; 第二行显示"PIC16F877A CCSC " .................... =============================================================================*/ .................... /////////////////////////////////////////////////////////////////////////////// .................... // MPLAB IDE V7.11 + CCS C3.18 .................... // LCD for MCD2-demo .................... // .................... // by LW7807@163.com .................... // 2005/06/20 .................... /////////////////////////////////////////////////////////////////////////////// .................... #include "16F877A.h" // PIC16F877 header file .................... //////// Standard Header file for the PIC16F877A device //////////////// .................... #device PIC16F877A .................... #list .................... .................... #use delay(clock=4000000) // for 4Mhz crystal * 005E: MOVLW 38 005F: MOVWF 04 0060: MOVF 00,W 0061: BTFSC 03.2 0062: GOTO 072 0063: MOVLW 01 0064: MOVWF 78 0065: CLRF 77 0066: DECFSZ 77,F 0067: GOTO 066 0068: DECFSZ 78,F 0069: GOTO 065 006A: MOVLW 4A 006B: MOVWF 77 006C: DECFSZ 77,F 006D: GOTO 06C 006E: NOP 006F: NOP 0070: DECFSZ 00,F 0071: GOTO 063 0072: RETLW 00 .................... #fuses XT, NOWDT, NOPROTECT, NOLVP // for debug mode .................... .................... #define PORT_A 0 // define for function output() .................... #define PORT_B 1 .................... #define PORT_C 2 .................... #define PORT_D 3 .................... #define PORT_E 4 .................... .................... .................... #define NCHAR_PER_LINE 16 // max char numbers per line .................... .................... #define LCD_RS PIN_A1 .................... #define LCD_RW PIN_A2 .................... #define LCD_E PIN_A3 .................... #define LCD_DAT PORT_C .................... .................... /////////////////////////////////////////////////////////// output() .................... //lcd data bus output .................... void output(int8 port, int8 dat) .................... { .................... switch(port) .................... { * 0004: MOVF 41,W 0005: MOVWF 77 0006: MOVF 77,F 0007: BTFSC 03.2 0008: GOTO 01A 0009: MOVLW 01 000A: SUBWF 77,W 000B: BTFSC 03.2 000C: GOTO 021 000D: MOVLW 02 000E: SUBWF 77,W 000F: BTFSC 03.2 0010: GOTO 028 0011: MOVLW 03 0012: SUBWF 77,W 0013: BTFSC 03.2 0014: GOTO 030 0015: MOVLW 04 0016: SUBWF 77,W 0017: BTFSC 03.2 0018: GOTO 037 0019: GOTO 03E .................... case PORT_A: output_a(dat); break; 001A: MOVLW 00 001B: BSF 03.5 001C: MOVWF 05 001D: BCF 03.5 001E: MOVF 42,W 001F: MOVWF 05 0020: GOTO 03F .................... case PORT_B: output_b(dat); break; 0021: MOVLW 00 0022: BSF 03.5 0023: MOVWF 06 0024: BCF 03.5 0025: MOVF 42,W 0026: MOVWF 06 0027: GOTO 03F .................... case PORT_C: output_c(dat); break; 0028: MOVLW 00 0029: MOVWF 20 002A: BSF 03.5 002B: MOVWF 07 002C: BCF 03.5 002D: MOVF 42,W 002E: MOVWF 07 002F: GOTO 03F * 0101: MOVLW FF 0102: MOVWF 20 .................... case PORT_D: output_d(dat); break; * 0030: MOVLW 00 0031: BSF 03.5 0032: MOVWF 08 0033: BCF 03.5 0034: MOVF 42,W 0035: MOVWF 08 0036: GOTO 03F .................... case PORT_E: output_e(dat); break; 0037: MOVLW 00 0038: BSF 03.5 0039: MOVWF 09 003A: BCF 03.5 003B: MOVF 42,W 003C: MOVWF 09 003D: GOTO 03F .................... default : //????port maybe error! .................... break; 003E: GOTO 03F .................... } .................... }//end output() 003F: RETLW 00 .................... .................... /////////////////////////////////////////////////////////// lcd_write_cmd() .................... // .................... void lcd_write_cmd(int8 cmd) .................... { .................... delay_us(400); 0040: MOVLW 85 0041: MOVWF 77 0042: DECFSZ 77,F 0043: GOTO 042 .................... output_low(LCD_RS); 0044: BSF 03.5 0045: BCF 05.1 0046: BCF 03.5 0047: BCF 05.1 .................... output_low(LCD_RW); 0048: BSF 03.5 0049: BCF 05.2 004A: BCF 03.5 004B: BCF 05.2 .................... output(LCD_DAT, cmd); 004C: MOVLW 02 004D: MOVWF 41 004E: MOVF 40,W 004F: MOVWF 42 0050: CALL 004 .................... .................... output_high(LCD_E); 0051: BSF 03.5 0052: BCF 05.3 0053: BCF 03.5 0054: BSF 05.3 .................... delay_us(400); 0055: MOVLW 85 0056: MOVWF 77 0057: DECFSZ 77,F 0058: GOTO 057 .................... output_low(LCD_E); 0059: BSF 03.5 005A: BCF 05.3 005B: BCF 03.5 005C: BCF 05.3 .................... }//end lcd_write_cmd() 005D: RETLW 00 .................... .................... /////////////////////////////////////////////////////////// lcd_write_dat() .................... // .................... void lcd_write_dat(int8 dat) .................... { .................... delay_us(400); * 00B0: MOVLW 85 00B1: MOVWF 77 00B2: DECFSZ 77,F 00B3: GOTO 0B2 .................... output_high(LCD_RS); 00B4: BSF 03.5 00B5: BCF 05.1 00B6: BCF 03.5 00B7: BSF 05.1 .................... output_low(LCD_RW); 00B8: BSF 03.5 00B9: BCF 05.2 00BA: BCF 03.5 00BB: BCF 05.2 .................... output(LCD_DAT, dat); 00BC: MOVLW 02 00BD: MOVWF 41 00BE: MOVF 40,W 00BF: MOVWF 42 00C0: CALL 004 .................... .................... output_high(LCD_E); 00C1: BSF 03.5 00C2: BCF 05.3 00C3: BCF 03.5 00C4: BSF 05.3 .................... delay_us(400); 00C5: MOVLW 85 00C6: MOVWF 77 00C7: DECFSZ 77,F 00C8: GOTO 0C7 .................... output_low(LCD_E); 00C9: BSF 03.5 00CA: BCF 05.3 00CB: BCF 03.5 00CC: BCF 05.3 .................... }//end lcd_write_dat() .................... .................... /////////////////////////////////////////////////////////// lcd_init() .................... // .................... void lcd_init(void) .................... { .................... output_low(LCD_E); // Let LCD E line low * 0073: BSF 03.5 0074: BCF 05.3 0075: BCF 03.5 0076: BCF 05.3 .................... .................... lcd_write_cmd(0x38); // LCD 16x2, 5x7, 8bits data 0077: MOVLW 38 0078: MOVWF 40 0079: CALL 040 .................... delay_ms(15); 007A: MOVLW 0F 007B: MOVWF 38 007C: CALL 05E .................... lcd_write_cmd(0x01); // Clear LCD display 007D: MOVLW 01 007E: MOVWF 40 007F: CALL 040 .................... delay_ms(10); 0080: MOVLW 0A 0081: MOVWF 38 0082: CALL 05E .................... lcd_write_cmd(0x0f); // Open display & current 0083: MOVLW 0F 0084: MOVWF 40 0085: CALL 040 .................... delay_ms(10); 0086: MOVLW 0A 0087: MOVWF 38 0088: CALL 05E .................... lcd_write_cmd(0x06); // Window fixed 0089: MOVLW 06 008A: MOVWF 40 008B: CALL 040 .................... delay_ms(10); 008C: MOVLW 0A 008D: MOVWF 38 008E: CALL 05E .................... }//end lcd_init() 008F: BCF 0A.3 0090: BCF 0A.4 0091: GOTO 12D (RETURN) .................... .................... /////////////////////////////////////////////////////////// lcd_display_char() .................... // .................... void lcd_display_char(int8 line, int8 pos, int8 ch) .................... { .................... int8 tmp; .................... .................... line = (line==0) ??0 : 1; 0092: MOVF 3C,F 0093: BTFSS 03.2 0094: GOTO 097 0095: MOVLW 00 0096: GOTO 098 0097: MOVLW 01 0098: MOVWF 3C .................... pos = (pos >NCHAR_PER_LINE) ??NCHAR_PER_LINE : pos; 0099: MOVF 3D,W 009A: SUBLW 10 009B: BTFSC 03.0 009C: GOTO 09F 009D: MOVLW 10 009E: GOTO 0A0 009F: MOVF 3D,W 00A0: MOVWF 3D .................... .................... tmp = 0x80 + 0x40*line + pos; 00A1: SWAPF 3C,W 00A2: MOVWF 77 00A3: RLF 77,F 00A4: RLF 77,F 00A5: MOVLW C0 00A6: ANDWF 77,F 00A7: MOVF 77,W 00A8: ADDLW 80 00A9: ADDWF 3D,W 00AA: MOVWF 3F .................... lcd_write_cmd(tmp); 00AB: MOVF 3F,W 00AC: MOVWF 40 00AD: CALL 040 .................... lcd_write_dat(ch); 00AE: MOVF 3E,W 00AF: MOVWF 40 .................... }//end lcd_display_char() * 00CD: RETLW 00 .................... .................... /////////////////////////////////////////////////////////// lcd_display_str() .................... // .................... void lcd_display_str(int8 line, char str[]) .................... { .................... int8 i; .................... .................... for(i=0; i<NCHAR_PER_LINE; i++) 00CE: CLRF 3A 00CF: MOVF 3A,W 00D0: SUBLW 0F 00D1: BTFSS 03.0 00D2: GOTO 0DC .................... { .................... lcd_display_char(line, i, ' '); 00D3: MOVF 38,W 00D4: MOVWF 3C 00D5: MOVF 3A,W 00D6: MOVWF 3D 00D7: MOVLW 20 00D8: MOVWF 3E 00D9: CALL 092 .................... } 00DA: INCF 3A,F 00DB: GOTO 0CF .................... for(i=0; i<NCHAR_PER_LINE; i++) 00DC: CLRF 3A 00DD: MOVF 3A,W 00DE: SUBLW 0F 00DF: BTFSS 03.0 00E0: GOTO 0F5 .................... { .................... if(str == '\0') break; 00E1: MOVF 39,W 00E2: ADDWF 3A,W 00E3: MOVWF 04 00E4: MOVF 00,F 00E5: BTFSC 03.2 00E6: GOTO 0F5 .................... lcd_display_char(line, i, str); 00E7: MOVF 39,W 00E8: ADDWF 3A,W 00E9: MOVWF 04 00EA: MOVF 00,W 00EB: MOVWF 3B 00EC: MOVF 38,W 00ED: MOVWF 3C 00EE: MOVF 3A,W 00EF: MOVWF 3D 00F0: MOVF 3B,W 00F1: MOVWF 3E 00F2: CALL 092 .................... } 00F3: INCF 3A,F 00F4: GOTO 0DD .................... }//end lcd_display_str() 00F5: BCF 0A.3 00F6: BCF 0A.4 00F7: GOTO 142 (RETURN) .................... .................... .................... /*===========================================================================*/ .................... void main(void) .................... { 00F8: CLRF 04 00F9: MOVLW 1F 00FA: ANDWF 03,F 00FB: MOVLW 06 00FC: BSF 03.5 00FD: MOVWF 1F 00FE: MOVLW 07 00FF: BCF 03.5 0100: MOVWF 1F .................... char LINE2[] = { "PIC16F877A CCSC LCD.C" }; * 0103: MOVLW 50 0104: MOVWF 21 0105: MOVLW 49 0106: MOVWF 22 0107: MOVLW 43 0108: MOVWF 23 0109: MOVLW 31 010A: MOVWF 24 010B: MOVLW 36 010C: MOVWF 25 010D: MOVLW 46 010E: MOVWF 26 010F: MOVLW 38 0110: MOVWF 27 0111: MOVLW 37 0112: MOVWF 28 0113: MOVWF 29 0114: MOVLW 41 0115: MOVWF 2A 0116: MOVLW 20 0117: MOVWF 2B 0118: MOVLW 43 0119: MOVWF 2C 011A: MOVWF 2D 011B: MOVLW 53 011C: MOVWF 2E 011D: MOVLW 43 011E: MOVWF 2F 011F: MOVLW 20 0120: MOVWF 30 0121: MOVLW 4C 0122: MOVWF 31 0123: MOVLW 43 0124: MOVWF 32 0125: MOVLW 44 0126: MOVWF 33 0127: MOVLW 2E 0128: MOVWF 34 0129: MOVLW 43 012A: MOVWF 35 012B: CLRF 36 .................... int8 i; .................... .................... lcd_init(); 012C: GOTO 073 .................... .................... for(i=0; i<NCHAR_PER_LINE; i++) 012D: CLRF 37 012E: MOVF 37,W 012F: SUBLW 0F 0130: BTFSS 03.0 0131: GOTO 13D .................... { .................... lcd_display_char(0, i, '0'+i); 0132: MOVLW 30 0133: ADDWF 37,W 0134: MOVWF 38 0135: CLRF 3C 0136: MOVF 37,W 0137: MOVWF 3D 0138: MOVF 38,W 0139: MOVWF 3E 013A: CALL 092 .................... } 013B: INCF 37,F 013C: GOTO 12E .................... //lcd_display_str(1, "PIC16F877A CCSC LCD.C") //CCSC can't compiler .................... lcd_display_str(1, LINE2); 013D: MOVLW 01 013E: MOVWF 38 013F: MOVLW 21 0140: MOVWF 39 0141: GOTO 0CE .................... }//end main() .................... 0142: SLEEP

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


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


加好友 发短信
等级:小学二年级 帖子:5 积分:151 威望:0 精华:0 注册:2005-12-18 10:48:00
[原创]  发帖心情 Post By:2005-12-18 19:59:00

各位先生: 谁能帮助我一个忙,编制一段PIC单片机程序,程序不大具体要求内容和报酬另谈.谢谢

e-mail地址:huiliu18@yahoo.com.cn



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