PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > Các ngôn ngữ lập trình khác (CCS C, HT PIC,...)

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 10-11-2008, 01:46 PM   #2
VuaHoa
Nhập môn đệ tử
 
Tham gia ngày: Oct 2007
Bài gửi: 2
:
Người huynh đệ, ngươi viết cẩu thả quá. Sai nhiều chỗ. Xem lại nhé:

Code:
#include <16f877a.h>

#device adc=8
#fuses nowdt,noprotect,put,xt
#use delay(clock=4000000)

#include <lcd.c>

#byte portb=0x06
#byte portd=0x08
#bit b0=portb.0
#bit b1=portb.1
#bit b2=portb.2
#bit b3=portb.3
#bit b4=portb.4
#bit b5=portb.5
#bit b6=portb.6
#bit b7=portb.7

int8 ch, pass;

void dat_pass();
void enter();
int8 get_pass();
void set_new_pass();

void kt_1()
{
    int8 kt;
    
    if(b5 == 0)
    { 
        delay_ms(10);
        if (b5 == 0);
        {
            kt = read_eeprom(0x00);
            if (kt == 0) 
                dat_pass();
            else      
                set_new_pass();
        }
    }
    if(b6 == 0)
    {
        delay_ms(10);
        if (b6 == 0)
            enter();
    }
}

void dat_pass()
{
    lcd_gotoxy(0, 1);
    lcd_putc("type your pass:");
    delay_ms(100);
    pass=get_pass();
    write_eeprom(0x00, pass);
    delay_ms(10);
    lcd_gotoxy(11, 1);
    lcd_putc("Great!!");
}

void set_new_pass()
{
    lcd_gotoxy(2, 1);
    lcd_putc("type old pass:");
    delay_ms(100);
    pass = get_pass();
    if (pass == read_eeprom(0x00))
    {
        delay_ms(10);
        lcd_gotoxy(4, 1);
        lcd_putc("New pass:");
        delay_ms(100);
        pass = get_pass();
        write_eeprom(0x00, pass);
        lcd_gotoxy(11, 1);
        lcd_putc("Great!!");
        delay_ms(100);
    }
    else 
    {
        lcd_gotoxy(7, 1);
        lcd_putc("Wrong pass!");
        delay_ms(100);      
    }
}

void enter()
{
    lcd_gotoxy(3, 1);
    lcd_putc("Password??");
    delay_ms(100);
    pass = get_pass();
   
    if(pass == read_eeprom(0x00))
    {
        lcd_gotoxy(4, 1);
        lcd_putc("You're welcom");
        delay_ms(100);      
    }
    else
    {
        lcd_gotoxy(7, 1);
        lcd_putc("Wrong pass!");
        delay_ms(100);      
    }
}

int8 get_pass()
{
    int8 pass;  
   
    if (b0 == 0)
    {
        delay_ms(10);
        if(b0 == 0)
            pass = 0x00;
    }
    if (b1 == 0)
    {
        delay_ms(10);
        if (b1 == 0)
            pass = 0x01;
    }
    if (b2 == 0)
    {
        delay_ms(10);
        if (b2 == 0)
            pass = 0x02;
    }
    if (b3 == 0)
    {
        delay_ms(10);
        if (b3 == 0)
            pass = 0x03;
    }
    return pass;
}
      
void ghi_eeprom(int8 ch)
{
    write_eeprom(0x00, ch);
}

int8 doc_eeprom()
{
    int8 ch;
   
    ch = read_eeprom(0x00);
    return ch;
}

void main()
{
    set_tris_d(0);
    set_tris_b(0xff);
    lcd_init();
   
    lcd_gotoxy(4, 1);
    lcd_putc("Welcom(^-^)");
}

thay đổi nội dung bởi: namqn, 10-11-2008 lúc 06:50 PM.
VuaHoa vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 04:24 AM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam