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

Trả lời
 
Ðiều Chỉnh Xếp Bài
Old 22-06-2010, 08:03 AM   #1
quanghung50
Nhập môn đệ tử
 
Tham gia ngày: May 2010
Bài gửi: 2
:
Smile help

Cac bac oi cho em hoi chut.
Tai sao trong doan code của em đến giờ hẹn giờ mà sao nó không báo thế.Em ngâm cứu mãi mà ko giải quyết dc. Help.

#include <16F877A.h>
#define RTC_CS(x) output_bit(PIN_C4,x) //RC0
#define RTC_AS(x) output_bit(PIN_C5,x) //RC1
#define RTC_RW(x) output_bit(PIN_C6,x) //RC2
#define RTC_DS(x) output_bit(PIN_C7,x) //RC3
#define RTC_DATA(x) output_b(x)
#define RTC_DATA_ input_b() //RB
#define HENGIO 5
#define HENPHUT 3
#define GIO 4
#define PHUT 2
#define GIAY 0
#define REGA 10
#define REGB 11
#define REGC 12
#define REGD 13
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOPUT //No Power Up Timer
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOCPD //No EE protection
#use delay(clock=20M)
#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#use fast_io(d)
#use fast_io(e)
#byte TMR1L=0x00e
#byte TMR1H=0X00F
#byte porta=0x05
#byte portb=0x06
#byte portc=0x07
#byte portd=0x08
#byte porte=0x09
#bit mot=porta.5 // chon chuan giao tiep intel
#BIT hen_gio=porte.0
#define chay_thuan portc=8; delay_us(5);
#define chay_nghich portc=4; delay_us(5);
#define stop portc=0;
#define tang input(pin_a0)
#define giam input(pin_a1)
#define enter input(pin_a2)
#define set_mode input(pin_a3)
#define gio1 input(pin_a4)
#define phut1 input(pin_c0)
#define giay1 input(pin_c1)
#define alam 1
#define set 2
#include <lcd.c>
unsigned char address;
unsigned char address_;unsigned char byte_;
unsigned char temp;


unsigned char gio_, phut_, giay_,gio_1, phut_1;
/////////////////////////////////////////
//khai bao cac ham
void RTC_Init();
void RTC_WaitUpdate();
void RTC_Stop();
void RTC_Run();
unsigned char RTC_Read(unsigned char);
void RTC_Write(unsigned char,unsigned char);
//void RTC_Write(unsigned char address,unsigned char byte)
void RTC_Settime(unsigned char,unsigned char,unsigned char);

void RTC_Gettime();
unsigned int value=0,hour=0,second=0,minute=0;
void RTC_Settime(unsigned char hour, unsigned char minute,unsigned char second)
{
RTC_Stop();
RTC_Write(GIO,hour);
RTC_Write(PHUT,minute);
RTC_Write(GIAY,second);


RTC_Run();
}
///////////////////////////////////
void RTC_Gettime()
{
//RTC_WaitUpdate();
gio_ = RTC_Read(GIO);
phut_ = RTC_Read(PHUT);
giay_ = RTC_Read(GIAY);
gio_1= RTC_Read(HENGIO);
phut_1= RTC_Read(HENPHUT);

}
/////////////////////////////////////
unsigned char RTC_Read(unsigned char address)
{
unsigned char temp;
set_tris_b(0);
set_tris_c(0);
RTC_AS(0);

RTC_DS(1);
RTC_RW(1);
RTC_AS(1);

//dua dia chi ra
RTC_DATA(address);delay_ms(1);
RTC_CS(0);delay_ms(1);

RTC_AS(0);delay_ms(1);
RTC_DS(0);

//doc du lieu ra
// RTC_DATA(0xFF);
set_tris_b(0xFF);

RTC_DS(0); delay_ms(1);
temp = RTC_DATA_;
RTC_DS(1);
RTC_CS(1);
RTC_AS(1);
return temp;
}
/////////////////////////////////////////
void RTC_Write(unsigned char address_,unsigned char byte_)
{
set_tris_b(0);
set_tris_c(0);
RTC_DS(1);
RTC_RW(1);
RTC_AS(0);

//dua dia chi ra
RTC_DATA(address_);delay_ms(1);
RTC_CS(0);
RTC_AS(1);delay_ms(1);
RTC_AS(0);delay_ms(1);
//dua du lieu ra
RTC_DATA(byte_);
RTC_RW(0);delay_ms(1);
RTC_RW(1);
RTC_CS(1);
RTC_AS(1);
}
//////////////////////////////////////////
void RTC_Init()
{

unsigned char temp;
mot=1;
RTC_CS(0);
set_tris_b(0);
set_tris_c(0);

//bat bo giao dong
RTC_Write(REGA,0x20);
//che do hien thi thoi gian la 24h
RTC_Write(REGB,0x0E);
//doc de xoa cac co
temp = RTC_Read(REGC);
}
//////////////////////////////////////////
void RTC_WaitUpdate()
{
unsigned char temp;
do
{
temp = RTC_Read(REGA);
temp = temp&0x80; //giu lai mot minh bit 7
}
while(temp!=0);
}
/////////////////////////////////////////
void RTC_Stop()
{
RTC_Write(REGB,0xA6);
}
////////////////////////////////////////
void RTC_Run()
{
RTC_Write(REGB,0x06);
}

void ChinhGio() //IE0_VECTOR 0 //0x03 External Interrupt 0
{
RTC_WaitUpdate();
gio_ = RTC_Read(GIO);
gio_++;
gio_=gio_%24;
RTC_Stop();
RTC_Write(GIO,gio_);
RTC_Run();
}
void ChinhPhut() //IE0_VECTOR 0 //0x03 External Interrupt 0
{
RTC_WaitUpdate();
phut_= RTC_Read(PHUT);
phut_++;
phut_=phut_%60;
RTC_Stop();
RTC_Write(PHUT,phut_);
RTC_Run();
}
void hengio1()
{
RTC_WaitUpdate();
gio_1= RTC_Read(HENGIO);
gio_1++;
gio_1=gio_1%24;
RTC_Stop();
RTC_Write(HENGIO,gio_1);
RTC_Run();
}
void henphut1()
{
RTC_WaitUpdate();
phut_1 = RTC_Read(HENPHUT);
phut_1++;
phut_1=phut_1%60;
RTC_Stop();
RTC_Write(HENPHUT,phut_1);
RTC_Run();

}
set_time()
{
value=0;
while(1)
{
lcd_gotoxy(1,1);
printf(lcd_putc,"1:set 2:time");
lcd_gotoxy(1,2);
printf(lcd_putc,"MODE=%u ",value);
if((tang)&&(value<2)) value++;
else if(giam&&(value>1)) value--;
//mode=value;
if(enter) break;
if(value==2) // chinh gio, phut
{

if(gio1)
{
ChinhGio(); // set gio

lcd_gotoxy(1,2);
printf(lcd_putc," setgio %u ",gio_); delay_ms(500);
if((gio_)&&(gio_<500)) gio_++;
//else if(giam) gio_--;
if (enter)break;
}
if(phut1)
{
ChinhPhut();
lcd_gotoxy(1,2);
printf(lcd_putc,"set phut %u ",phut_); delay_ms(500);
if((phut_)&&(phut_<500)) phut_++;
//else if(giam) phut_--;
if (enter)break;
}
}
if (value==1) // thiet dat thoi gian dong mo cua .
{
if(gio1)
{
hengio1(); // set gio
lcd_gotoxy(1,2);
printf(lcd_putc," setgio %u",gio_1); delay_ms(500);
// if((tang)&&(gio_<500)) gio_++;
//else if(giam) gio_1--;
if (enter)break;
}
if(phut1)
{
henphut1();
lcd_gotoxy(1,2);
printf(lcd_putc,"set %u gio %u phut ",gio_1,phut_1); delay_ms(500);
if (enter)break;
if(hen_gio){
lcd_gotoxy(1,2);
printf(lcd_putc," dong cua ");delay_ms(5000);
}
}
}
}
}
void main()
{
//int8 cnt=0;
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

// TODO: USER CODE!!
RTC_Init();
// RTC_Settime(07,56,00);
lcd_init();

set_tris_b(0xFF);
set_adc_channel(0);
RTC_Gettime();

RTC_Gettime();

while(1){
//adc= read_adc();

delay_ms(300);
RTC_Gettime();
lcd_gotoxy(1,1);
printf(LCD_putc,"%c%c : %c%c : %c%c",(gio_/10)+'0',(gio_%10)+'0',(phut_/10)+'0',(phut_%10)+'0',(giay_/10)+'0',(giay_%10)+'0');
// lcd_gotoxy(2,2);printf(LCD_putc,"Tick=%3u",cnt++);


if(set_mode)
{
while(set_mode){
set_time();

if(hen_gio){
lcd_gotoxy(1,2);
printf(lcd_putc," dong cua ");delay_ms(5000);

chay_thuan;
delay_ms(5000);
printf(lcd_putc,"\fMo Cua"); delay_ms(5000);
stop;
}



}
}
}
}
quanghung50 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 22-06-2010, 09:02 AM   #2
quanghung50
Nhập môn đệ tử
 
Tham gia ngày: May 2010
Bài gửi: 2
:
giúp em với, em dung` pic 16f877A , RTC Ds12C887, LCD
quanghung50 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Trả lờ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à 11:31 PM.


Đượ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