PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > PIC - Thiết kế và Ứng dụng

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

PIC - Thiết kế và Ứng dụng Ý tưởng cho các sản phẩm sử dụng PIC/dsPIC và các sản phẩm của Microchip

Trả lời
 
Ðiều Chỉnh Xếp Bài
Old 12-05-2012, 01:44 AM   #1
ducminh82
Nhập môn đệ tử
 
Tham gia ngày: Jun 2010
Bài gửi: 6
:
Post Giúp với, không hiểu sao mạch này sai chỗ nào nữa

E CÓ CODE NÀY KHÔNG BÍT SAI Ở ĐÂU NỮA MÀ SAO NẠP VÔ PIC KHÔNG CHẠY ĐÚNG
MONG CÁC BÁC XEM SAI CHỖ NÀO ĐỂ E SỬA
THANK TRƯỚC!
ĐÂY: http://www.mediafire.com/?oq725q0eq227pne
ducminh82 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 12-05-2012, 05:47 AM   #2
hatuan296
Làm quen với PIC
 
Tham gia ngày: Oct 2005
Nơi Cư Ngụ: Hcm
Bài gửi: 160
:
Mình chỉ mới xem sơ đồ mạch và thấy phần 4 nút bấm của bạn thiết kế rất khác so với nút reset . Đây là ý của bạn chăng ?
hatuan296 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 12-05-2012, 06:37 PM   #3
longtu
Đệ tử 6 túi
 
longtu's Avatar
 
Tham gia ngày: Jul 2007
Bài gửi: 146
:
Send a message via Yahoo to longtu
Thông thường, các bài viết như vậy rất ít người tra lời. Vi phải mắt công down tài liệu về...Hãy tìm cách post hình ảnh, code lên ngay trong bài viết. Khi đó có thể thấy ngay vấn để của bạn.

Thân,
__________________
--------------------------------------------------------------------------------------
Phùng Minh Tuân
Email: tuan.phmt@gmail.com
"Cuộc đời sóng gió nuôi ta lớn
Bao lần thất bại dạy ta khôn".
longtu vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 12-05-2012, 09:01 PM   #4
ducminh82
Nhập môn đệ tử
 
Tham gia ngày: Jun 2010
Bài gửi: 6
:
À, chỗ này có lẽ bị nhầm,mình sẽ sủa lại
đây là code của nó:

#include <16F877a.h> // KHAI BAO SU DUNG PIC 16F877A

#include <def_877a.h> // FILE DINH NGHIA CAC THANH GHI VA CAC BIT

#device *=16 adc=10 // KHAI BAO SU DUNG CON TRO 16 BIT VA ADC 10 BIT
// KHAI BAO CAU HINH CHO PIC 16F877A
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP,NOCPD, NOWRT
// KHAI BAO SU DUNG DELAY VOI TAN SO DAO DONG NGOAI
#use delay(clock=12000000)

#include <DS1307.c>

/////////////////////////////////////////////////////////////////////////////

byte sec,min,hour,day,month,year;
byte const MAP[10] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90 };
byte TG1,TG2,TG3,TG4,TG5,TG6; //bien hien led trung gian
byte day1, day2, month1, month2, year1, year2, year3;

#bit SW1 = 0x08.0 // D0 - chon che do chinh gio, phut, giay
#bit SW2 = 0x08.1 // D1 - tang thoi gian
#bit SW3 = 0x08.2 // D2 - giam thoi gian
#bit SW4 = 0x08.3 // D3 - clear tinh trang
#bit led1= 0x09.0
#bit led2= 0x09.1// hien thi led don
#bit ngc = 0x08.5 // ngay- hang chuc
#bit ngd = 0x08.4 // ngay- hang don vi
#bit thc = 0x09.2 // thang- hang chuc
#bit thd = 0x07.1 // thang- hang don vi
#bit nat = 0x07.7 // nam- hang tram
#bit nac = 0x07.6 // nam- hang chuc
#bit nad = 0x07.5 // nam- hang don vi
#bit gic = 0x05.5 // gio- hang chuc
#bit gid = 0x05.4 // gio- hang don vi
#bit pc = 0x05.3 // phut- hang chuc
#bit pd = 0x05.2 // phut- hang don vi
#bit gc = 0x05.1 // giay- hang chuc
#bit gd = 0x07.0 // giay- hang don vi
#bit nc = 0x08.7 // nhiet do- hang chuc
#bit nd = 0x08.6 // nhiet do- hang don vi

int8 high,low;
float value;
int16 i;
byte chinh_phut, chinh_gio, chinh_day, chinh_month, chinh_year;

void update_1307();// CAP NHAT DS1307

void set_sec();// CHINH GIAY
void set_min();// CHINH PHUT
void set_hour();// CHINH GIO
void set_day();//chinh day
void set_month(); //chinh month
void set_year(); // chinh year

void read_time(); // CHUONG TRINH CON DOC THOI GIAN DS1307
void update_time();// CHUONG TRINH CON CAP NHAT THOI GIAN
void display();// CHUONG TRINH CON HIEN THI

void convert_bcd(int8 x)
{
low=x%10; // CHU SO HANG DON VI
high=x/10; // CHU SO HANG CHUC

}

//////////////////////////////////////////////////////////////////////////
// BAT DAU CHUONG TRINH CHINH////////////////////////////////////////////

void main()
{
byte u;
set_Tris_d(0x0F);
set_Tris_b(0x00);
set_Tris_a(0x01);
set_Tris_c(0x18);
set_Tris_e(0x00);
init_ds1307();
u=read_ds1307(0);
sec=u & 0x0F;

/////////////////////////////////////////

setup_adc(ADC_CLOCK_INTERNAL); // THIET LAP THOI GIAN LAY MAU BANG XUNG CLOCK
setup_adc_ports(AN0); // THIET LAP CHAN AN0 LA CHAN VAO ADC
set_ADC_channel(0) ;
delay_us(10); // TRE 10US

value=(float)read_adc(); // DOC GIA TRI ADC
value = (value-558.5)/2.048;
convert_bcd((int8)value); // GOI CHUONG TRINH CON CONVERT_BCD


//////////////////////////////////////////////

write_ds1307(0,sec);// ket noi dong ho(bit7=0)
chinh_gio=0; chinh_year=0; chinh_day=0; chinh_phut=0;chinh_month=0;
ngc=1;ngd=1;thc=1;thd=1;nat=1; nac=1; nad=1; gic=1; gid=1; pc=1; pd=1; gc=1; gd=1;nc=1;nd=1;
year3=0;
while(true)
{
i++;
read_time();
display();
if(hour==0x18||hour==0x19||hour==0x20||hour==0x21| |hour==0x22||hour==0x23||hour==0x00||hour==0x01||h our==0x02||hour==0x03||hour==0x04||hour==0x05)
{
led1=1; led2=1;
}
else
{
led1=0; led2=0;
}

if(sw1==0)
{
if(chinh_phut==0&&sw4==1)
{
while(sw1==0) {}
set_min(); chinh_phut=1;
}
else if(chinh_gio==0&&sw4==1)
{
while(sw1==0) {}
set_hour(); chinh_gio=1;
}
else if(chinh_day==0&&sw4==1)
{
while(sw1==0) {}
set_day(); chinh_day=1;
}
else if(chinh_month==0&&sw4==1)
{
while(sw1==0){}
set_month(); chinh_month=1;
}
else if(chinh_year==0&&sw4==1)
{
while(sw1==0){}
set_year(); chinh_year=1;
}
else if(chinh_phut==1&&chinh_gio==1&&chinh_day==1&&chin h_month==1&&chinh_year==1)
{
chinh_phut=0; chinh_gio=0; chinh_day=0; chinh_month=0; chinh_year=0;
}
}

if(sw4==0)
{
chinh_gio=0; chinh_year=0; chinh_day=0; chinh_phut=0;chinh_month=0;
}

}
}
//////////////////////////////////////////////////

// CHUONG TRINH CON HIEN THI RA LED 7 DOAN

/////////////////////////////////////////

void read_time()
{
sec = read_DS1307(0);
min = read_DS1307(1);
hour = read_DS1307(2);
day = read_DS1307(4);
month= read_DS1307(5);
year= read_DS1307(6);


value =(float) read_adc();
value = (value-558.5)/2.048;///ADC_10_bit: C= ( reading-558.6)/ 2.048
if (i==500)
{
convert_bcd((int8)value);
i=0;
}

update_time();
}

/////////////////////////////////////////////////////

void update_1307()
{
write_DS1307(0,sec);
write_DS1307(1,min);
write_DS1307(2,hour);
write_DS1307(4,day);
write_DS1307(5,month);
write_DS1307(6,year);
}

////////////////////////////////////////////////////
void update_time()
{

TG1= sec & 0x0F;
TG2=(sec & 0xF0)>>4; //convert to BCD SEC
TG3= min & 0x0F;
TG4=(min & 0xF0)>>4; //convert to BCD MIN
TG5= hour & 0x0F;
TG6=(hour & 0x30)>>4; //convert to BCD HOUR
///////////////////////////////////////////////
day1= day&0x0F;
day2= (day&0x30)>>4;
month1= month&0x0F;
month2= (month&0x10)>>4;
year1= year&0x0F;
year2= (year&0xF0)>>4;
}

//////////////////////////////////////////////////////

void set_min()
{
ngc=1;ngd=1;thc=1;thd=1;nat=1; nac=1; nad=1; gic=1; gid=1; pc=1; pd=1; gc=1; gd=1;
min= read_DS1307(1);
TG3= min & 0x0F;
TG4=(min & 0xF0)>>4; //convert to BCD MIN
while(sw1==1&&sw4==1)
{

portb= MAP[TG3]; pd=0; delay_us(500); pd=1;
portb= MAP[TG4]; pc=0; delay_us(500); pc=1;

if(sw2==0)
{
while(sw2==0) {}
if(TG4==5&&TG3==9) { TG4=0; TG3=0;}
else if(TG3==9) { TG4++; TG3=0;}
else TG3++;
}
if(sw3==0)
{
while(sw3==0) {}
if(TG4==0&&TG3==0) {TG4=5; TG3=9;}
else if(TG3==0) {TG4--; TG3=9;}
else TG3--;
}
min= (TG4<<4) + TG3;
write_DS1307(1,min);
delay_us(10);
}
// ngc=0; ngd=0; thc=0; thd=0; nat=0; nac=0; nad=0; gic=0; gid=0; pc=0; pd=0; gc=0; gd=0;


}

////////////////////////////////////////////////////

void set_hour()
{
ngc=1;ngd=1;thc=1;thd=1;nat=1; nac=1; nad=1; gic=1; gid=1; pc=1; pd=1; gc=1; gd=1;
hour= read_DS1307(2);
TG5= hour & 0x0F;
TG6=(hour & 0x30)>>4; //convert to BCD MIN
while(sw1==1&&sw4==1)
{

portb= MAP[TG5]; gid=0; delay_us(500); gid=1;
portb= MAP[TG6]; gic=0; delay_us(500); gic=1;

if(sw2==0)
{
while(sw2==0) {}
if(TG6==2&&TG5==4) { TG6=0;TG5=0;}
else if(TG5==9) { TG6++; TG5=0;}
else TG5++;
}
if(sw3==0)
{
while(sw3==0) {}
if(TG6==0&&TG5==0) {TG6=2; TG5=4;}
else if(TG5==0) {TG6--; TG5=9;}
else TG5--;
}
hour= (TG6<<4) + TG5;
write_DS1307(2,hour);
delay_us(10);
}

// ngc=0; ngd=0; thc=0; thd=0; nat=0; nac=0; nad=0; gic=0; gid=0; pc=0; pd=0; gc=0; gd=0;


}
/////////////////////////////////////////////

void set_day()
{
ngc=1;ngd=1;thc=1;thd=1;nat=1; nac=1; nad=1; gic=1; gid=1; pc=1; pd=1; gc=1; gd=1;
day= read_DS1307(4);
day1= day & 0x0F;
day2=(day & 0x30)>>4; //convert to BCD MIN
while(sw1==1&&sw4==1)
{

portb= MAP[day1]; ngd=0; delay_us(500); ngd=1;
portb= MAP[day2]; ngc=0; delay_us(500); ngc=1;

if(sw2==0)
{
while(sw2==0) {}
if(day2==3&&day1==1) { day2=0; day1=0;}
else if(day1==9) { day2++; day1=0;}
else day1++;
}
if(sw3==0)
{
while(sw3==0) {}
if(day2==0&&day1==0) {day2=3; day1=1;}
else if(day1==0) {day2--; day1=9;}
else day1--;
}
day= (day2<<4) + day1;
write_DS1307(4,day);
delay_us(10);
}

// ngc=0; ngd=0; thc=0; thd=0; nat=0; nac=0; nad=0; gic=0; gid=0; pc=0; pd=0; gc=0; gd=0;

}

/////////////////////////////////////////////

void set_month()
{
ngc=1;ngd=1;thc=1;thd=1;nat=1; nac=1; nad=1; gic=1; gid=1; pc=1; pd=1; gc=1; gd=1;
month= read_DS1307(5);
month1= month & 0x0F;
month2=(month & 0x10)>>4; //convert to BCD MIN
while(sw1==1&&sw4==1)
{

portb= MAP[month1]; thd=0; delay_us(500); thd=1;
portb= MAP[month2]; thc=0; delay_us(500); thc=1;

if(sw2==0)
{
while(sw2==0) {}
if(month2==1&&month1==2) { month2=0; month1=0;}
else if(month1==9) { month2++; month1=0;}
else month1++;
}
if(sw3==0)
{
while(sw3==0) {}
if(month2==0&&month1==0) {month2=1; month1=2;}
else if(month1==0) {month2--; month1=9;}
else month1--;
}
month= (month2<<4) + month1;
write_DS1307(5,month);
delay_us(10);
}

// ngc=0; ngd=0; thc=0; thd=0; nat=0; nac=0; nad=0; gic=0; gid=0; pc=0; pd=0; gc=0; gd=0;
}

////////////////////////////////////////////

void set_year()
{
ngc=1;ngd=1;thc=1;thd=1;nat=1; nac=1; nad=1; gic=1; gid=1; pc=1; pd=1; gc=1; gd=1;
year= read_DS1307(6);
year1= year & 0x0F;
year2=(year & 0xF0)>>4; //convert to BCD MIN
while(sw1==1&&sw4==1)
{

portb= MAP[year1]; nad=0; delay_us(500); nd=1;
portb= MAP[year2]; nac=0; delay_us(500); nac=1;

if(sw2==0)
{
while(sw2==0) {}
if(year3==9&&year2==9&&year1==9) {year3=0;year2=0;year1=0;}
if(year2==9&&year1==9) { year3++;year2=0;year1=0;}
else if(year1==9) { year2++; year1=0;}
else year1++;
}
if(sw3==0)
{
while(sw3==0) {}
if(year3==0&&year2==0&&year1==0) { year3=9;year2=9;year1=9;}
if(year2==0&&year1==0) {year3--; year2=9;year1=9;}
else if(year1==0) {year2--; year1=9;}
else year1--;
}
year= ( year2<<4) + year1;
write_DS1307(6,year);
delay_us(10);
}

// ngc=0; ngd=0; thc=0; thd=0; nat=0; nac=0; nad=0; gic=0; gid=0; pc=0; pd=0; gc=0; gd=0;

}
//////////////////////////////////////////////

void display()
{
// sec - min - hour
PortB=MAP[TG6];
gic=0;
delay_us(500);
gic=1;

PortB=MAP[TG5];
gid=0;
delay_us(500);
gid=1;

PortB=MAP[TG4];
pc=0;
delay_us(500);
pc=1;

PortB=MAP[TG3];
pd=0;
delay_us(500);
pd=1;

PortB=MAP[TG2];
gc=0;
delay_us(500);
gc=1;

PortB=MAP[TG1];
gd=0;
delay_us(500);
gd=1;

// day- month- year
PortB= MAP[year3];
nat=0;
delay_us(500);
nat=1;

PortB=MAP[year2];
nac=0;
delay_us(500);
nac=1;

PortB=MAP[year1];
nad=0;
delay_us(500);
nad=1;

PortB=MAP[month2];
thc=0;
delay_us(500);
thc=1;

PortB=MAP[month1];
thd=0;
delay_us(500);
thd=1;

PortB=MAP[day2];
ngc=0;
delay_us(500);
ngc=1;

PortB=MAP[day1];
ngd=0;
delay_us(500);
ngd=1;


// nhiet do
PORTB=MAP[high];
nc=0;
delay_us(500);
nc=1;

PORTB=MAP[low];
nd=0;
delay_us(500);
nd=1;
/////////////////////////////////////////////////


}
ducminh82 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 12-05-2012, 09:02 PM   #5
ducminh82
Nhập môn đệ tử
 
Tham gia ngày: Jun 2010
Bài gửi: 6
:
hình như thiếu phần quét led phải không nhỉ?
ducminh82 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Trả lời

Ðiều Chỉnh
Xếp Bài

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à 08:30 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