PIC Vietnam

Go Back   PIC Vietnam > Ban Điều Hành > Đóng góp ý kiến

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

Đóng góp ý kiến Nơi tiếp nhận những ý kiến đóng góp của thành viên

Trả lời
 
Ðiều Chỉnh Xếp Bài
Old 15-10-2008, 12:05 PM   #1
const_nos
Đệ tử 2 túi
 
Tham gia ngày: Jul 2008
Bài gửi: 33
:
Post bài trên picvietnam

mình là thành viên mới.Mình chưa biết cách post bài len diễn đàn và đính kèm theo tạp tin hay một chương trình đã viết. Mình có đọc luồng hướng dẫn nhưng chưa tìm ra cách post.Các bạn vui lòng chỉ giúp mình với. đang rất cần. thank!
const_nos vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 15-10-2008, 01:11 PM   #2
falleaf
PIC Bang chủ
 
falleaf's Avatar
 
Tham gia ngày: May 2005
Bài gửi: 2,631
:
Send a message via Yahoo to falleaf
http://dientuvietnam.net/forums/announcement.php?f=145

Đọc nội dung ở đây, picvietnam và dientuvietnam hoạt động tương tự nhau.

Chúc vui
falleaf vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 14-06-2011, 01:38 AM   #3
alycuong
Đệ tử 1 túi
 
Tham gia ngày: Apr 2010
Bài gửi: 16
:
Sao cái khung viết bài của mình nó trống trơn ah2, k có cái thanh tool công cụ: im đậm, nghiêng, màu chữ, dẫn link .....,Chỉ có cái khung màu trắng thôi. Bên dientuvietnem thì có nhưng picvietnam thi 2 k có.

alycuong vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 15-06-2011, 01:39 PM   #4
an1088
Nhập môn đệ tử
 
Tham gia ngày: Oct 2010
Bài gửi: 2
:
anh em giup do minh cai ..thanhks nhieu

minh dang viet ve de tai ung dung logic mo trong do nhiet do dung pic 16f887 nhung minh viet no bi bao loi hoai ..anh e iup minh sua cai nhen...
code:

#include <htc.h>
#include<stdio.h>
//#include<stdlib.h> //thu vien dung cho printf
#include "lcd.h"
#include <string.h>
#include<math.h>
//#include<isntrin.h>
//thu vien dung cho LCD
__CONFIG(INTIO & WDTDIS & PWRTEN & MCLREN & UNPROTECT & DUNPROTECT & BORDIS & IESODIS & FCMDIS & LVPDIS);
#define _XTAL_FREQ 4000000
unsigned long adc_val=0;
unsigned int ResA0 ;
//unsigned char count;
unsigned int SetTemp =30,CurrentTemp;
int dt,dm,DATA,muy =50;
unsigned int dCycle=0,dCycleC=0xFFFF;
float dtemp;
void ClearDisplay(void);
void BeginOne(void);
void BeginTwo(void);
int am_nhieu(int error);
int am_it(int error);
int bang_khong(int error);
int duong_it(int error);
int duong_nhieu(int error);
void inference(void);
void refuzzy(void);
int min(int x0,int y0);
int max2(int x0,int y0);
int max5(int x1,int x2,int x3,int x4,int x5);
unsigned int khong[101],nho[101],trung_binh[101],lon[101],rat_lon[101];
unsigned int R1[101],R2[101],R3[101],R4[101],R5[101],R[101];
int count=0;
void interrupt isr() {
unsigned char temp;
if(RBIE&&RBIF) {
RBIF = 0;
// CCP1CON = 0x0C;
// CCP1CON = 0x0C;
ClearDisplay();
BeginOne();

printf("Set: %d C\n",SetTemp);
printf("Set Up Down Ok");
do
{
temp = PORTB & 0x07;
_delay(3000);
if(temp==0x06)
{
if(SetTemp < 130)
{
SetTemp++;

}

// khong che settemp khong vuot qua 130
if(SetTemp>130)
{
SetTemp=130;
}
ClearDisplay();
BeginOne();
printf("Set: %d C\n",SetTemp);
printf("Set Up Down Ok");
}
//khong che settemp khong nho hon 30
if(temp == 0x05)
{
if(SetTemp > 30)
{
SetTemp--;

}

if(SetTemp<30)
{
SetTemp=30;
}
ClearDisplay();
BeginOne();

printf("Set: %d C\n",SetTemp);
printf("Set Up Down Ok");

}

}
while(temp!=0x03);
}

}


void main()
{

/*khoi tao */
//1.Khoi tao IO port
ANSEL = ANSELH = 0; //Tat ca cac chan la Digital, (dung LCD)

ANS0 =1;
ANS5 = 0; // Chan motor enable la digital IO
TRISE0 = 0; // Chan motor enable la digital output
RE0 = 1; // logic 1, cho phep motor chaY

TRISC1 = 0; // chan CCP2 la output
TRISC2 = 0; // chan CCP1 la output
/* INTF=0; //
INTE=1; //
INTEDG=0;*/
WPUB=0x03; //noi dien tro pullup vao RB0
RBPU=0; //cho phep pull up tich cuc muc thap nam trong thanh ghi OPTION_REG

IOCB=0x03; //cho phep ngat tren 3 chan RB012
RBIF=0; //Xoa co ngat
RBIE=1;
//2.Khoi tao LCD
lcd_init();
// ANS3=1;
//3.Khoi tao VA CAU HINH ADC
//+Chon nguon xung Clock
ADCS0=ADCS1=1; //Chon Frc
//+Chon dien ap tham chieu Vref+ = 5V, Vref- = 0: AD 10-bit, chia muc 5V = 1024 muc
VCFG0 = VCFG1=0;
//+Chon kenh can do
CHS0 = CHS1 = 0; //Ban dau chon kenh 0
CHS2 = CHS3=0;
//+Canh phai ket qua
ADFM = 1;
// //+Cho phep module AD hoat dong
ADON = 1;
// cau hinh timer 2
T2CON = 0; // prescaler = 1:1; postscaler = 1:1
TMR2ON = 1;
PR2 = 99; // Thoi gian timer tran: T = Tosc * prescaler * (PR2+1)
// = 1us * 1 * 200 = 200us
// => tan so PWM = 1/T = 5KHz
//4.Chuong trinh chinh, vong lap vo han
GIE=1; //ngat toan cuc
while(1) {
//+Tien hanh do kenh 0
CHS0 = 0; //Chon kenh 0
GODONE = 1; //Yeu cau Module ADC chuyen doi;o09j,/
while(GODONE); //Lap tai day chung nao GODONE van con bang 1
//Nghia la GODONE bi xoa thi thoat khoi vong lap (GODONE bi xoa khi AD chuyen doi xong)

//+Lay ket qua do tu kenh 0
ResA0 = (ADRESH<<8);
ResA0 += ADRESL;
CurrentTemp= 0.49*ResA0;
dt = SetTemp-CurrentTemp;
inference();
refuzzy();
/* muy = muy + dm;
if(muy>99)
{
muy=99;
}
if(muy<1)
{
muy=1;
}
dtemp = ((float) (muy*65535))/100;
dCycle = (unsigned int)(dtemp);
dCycle = ~dCycle;*/


// CHS0=0;
__delay_us(5); // cho ADC lay mau
GODONE = 1;
while(GODONE);

adc_val = ADRESL;
adc_val |= ((unsigned int)ADRESH << 8);//X256
adc_val = adc_val* 200/ 1023;

if(adc_val<200){
CCP1CON = 0x0C; // cau hinh CCP1 la PWM
CCP2CON = 0; // tat CCP2, chan RC1 do PORTC dieu khien
CCPR1L =50-adc_val; // set duty cho CCP1
}else{
CCP2CON = 0x0C; // cau hinh CCP2 la PWM
CCP1CON = 0; // tat CCP1, chan RC2 do PORTC dieu khien
CCPR2L =adc_val-50; // set duty cho CCP2
}
ClearDisplay();
BeginOne();
// lcd_gotoxy(0,0);
printf("set:%dC\n",SetTemp);
printf("\nCurrent:%dC",CurrentTemp);
// sendchar(CurrentTemp);
// request(); //
_delay(100000);
}
}

int am_nhieu(int error)
{
if(error<= -120)
return(100);
if((error>-120)&&(error<-60))
return((int) (5*(-60-error)/3));
if(count>= -60)
return(0);
}
int am_it(int error)
{
if(error<= -120)
return(0);
if((error>-120)&&(error<=-60))
return((int) (5*(error+120)/3));
if((error>-60)&&(error<0))
return((int) (5*(-error)/3));
if(count>= 0)
return(0);
}
int bang_khong(int error)
{
if(error<= -60)
return(0);
if((error>-60)&&(error<=0))
return((int) (5*(error+60)/3));
if((error>0)&&(error<60))
return((int) (5*(60-error)/3));
if(error>= 60)
return(0);
}
int duong_it(int error)
{
if(error<= 0)
return(0);
if((error>0)&&(error<=60))
return((int) (5*(error)/3));
if((error>60)&&(error<120))
return((int) (5*(120-error)/3));
if(error>= 120)
return(0);
}
int duong_nhieu(int error)
{
if(error<= 60)
return(0);
if((error>60)&&(error<120))
return((int) (5*(error-60)/3));
if(count>= 120)
return(100);
}
void inference(void)
{
int temp1,temp2,temp3,temp4,temp5;
temp1 = am_nhieu(dt);
temp2 = am_it(dt);
temp3 = bang_khong(dt);
temp4 = duong_it(dt);
temp5 = duong_nhieu(dt);
for(count =0;count<100;count++)
{
R1[count]=min(temp1,rat_lon[count]);
R2[count]=min(temp2,lon[count]);
R3[count]=min(temp3,trung_binh[count]);
R4[count]=min(temp4,nho[count]);
R5[count]=min(temp5,khong[count]);
}
for(count =0;count<100;count++)
{
R[count]= max5(R1[count],R2[count],R3[count],R4[count],R5[count]);

}

}
void refuzzy(void)
{
long int temp1 =0,temp2=0;
for(count =0;count<100;count++)
{
temp1+=count*R[count];
temp2+=R[count];
}
dm =(int) ((float) temp1/temp2 - 50);
}
void delay(long int wait)
{
unsigned int count;
for(count=0;count<wait;count++);
}
int max2(int x0,int y0)
{
if(x0<y0) return(y0);
if(x0>=y0) return(x0);
}
int max5(int x1,int x2,int x3,int x4,int x5)
{
int temp1,temp2,temp3;
temp1 = max2(x1,x2);
temp2 = max2(x3,x4);
temp3 = max2(temp1,temp2);
return(max2(temp3,x5));
}
int min(int x0,int y0)
{
if(x0<y0) return(x0);
if(x0>=y0) return(y0);
}
void BeginOne(void)
{
DATA = 0x80;
// ExeLCD();
lcd_init();
}
void BeginTwo(void)
{
DATA = 0xC0;
// ExeLCD();
lcd_init();
}
void ClearDisplay(void)
{
DATA = 0x01;
// ExeLCD();
lcd_init();
BeginOne();

}
/*
* Ham nay phuc vu xuat du lieu cho ham printf
*/
void putch(char c)
{
lcd_putc(c);
}
-----------------------------------------
loi bao :
Executing: "C:\Program Files\HI-TECH Software\PICC\9.80\bin\picc.exe" --pass1 "D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c" -q --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Warning [356] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 152.24 implicit conversion of float to integer
Warning [343] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 207.1 implicit return at end of non-void function
Warning [343] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 218.1 implicit return at end of non-void function
Warning [343] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 229.1 implicit return at end of non-void function
Warning [343] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 240.1 implicit return at end of non-void function
Warning [343] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 249.1 implicit return at end of non-void function
Warning [343] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 292.1 implicit return at end of non-void function
Warning [343] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 305.1 implicit return at end of non-void function
Executing: "C:\Program Files\HI-TECH Software\PICC\9.80\bin\picc.exe" --pass1 "D:\nhiet do pic\chuong trinh\New Folder (3)\lcd.c" -q --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Executing: "C:\Program Files\HI-TECH Software\PICC\9.80\bin\picc.exe" -o16f8873.cof -m16f8873.map --summary=default,-psect,-class,+mem,-hex --output=default,-inhx032 16f8873.p1 lcd.p1 --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
(1273) Omniscient Code Generation not available in Lite mode (warning)
HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode) V9.80
Copyright (C) 2010 Microchip Technology Inc.
Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 32. could not find space (202 bytes) for variable _khong
Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 32. could not find space (202 bytes) for variable _nho
Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 32. could not find space (202 bytes) for variable _trung_binh
Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 32. could not find space (202 bytes) for variable _lon
Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 32. could not find space (202 bytes) for variable _rat_lon
Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 33. could not find space (202 bytes) for variable _R1
Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 33. could not find space (202 bytes) for variable _R2
Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 33. could not find space (202 bytes) for variable _R3
Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 33. could not find space (202 bytes) for variable _R4
Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 33. could not find space (202 bytes) for variable _R5
Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 33. could not find space (202 bytes) for variable _R
Advisory[1] too many errors (11)

********** Build failed! **********
an1088 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 15-11-2013, 09:59 PM   #5
nguyenthanhquat
Nhập môn đệ tử
 
Tham gia ngày: Jul 2013
Bài gửi: 4
:
Xin code tiny bootloader cho pic16f877a qua giao tiếp RS485

mình mới tìm hiều về tiny bootloader và đã thử thành công qua giao tiếp RS232, hiện tại mình đang sử dụng giao tiếp RS485 và có ý tường là dùng tiny bootloader qua RS485 (mình kết nối maax485 với chân RX, TX của pic, chân điều khiển Max485 là RC5, thạch anh 20M, tốc độ 9600) mình ko biết nhieuf về lập trình asm nên ko biết sửa code trong tiny bootloader cho phù hợp, mong các bạn giúp đỡ
nguyenthanhquat vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 28-02-2014, 10:04 AM   #6
chauphuoc
Nhập môn đệ tử
 
Tham gia ngày: Feb 2014
Bài gửi: 2
:
Minh dag lam Do An ve "ĐIỀU KHIỂN ĐÓNG MỞ CỬA BẰNG THẺ RFID" dùng Pic 18F4680 va dùng phần mềm MPLAB
C18, mà không hiểu sao minh viết xong rùi dịch thì nó cứ báo lỗi hoài ak.mih tìm hoài mà cũng chưa ra được nữa, a e xem đoạn COSD minh viết bên dưới có bị thiếu sót hay sai chỗ nào thì sữa lại giúp minh với. Nếu a,e nào có cài MPLAB C18 thì sẵng tiện dịch đoạn COSD này giúp minh.Thank very much!

#include "DOOR_RFID.h"

INT1 KHOA =0,BAO_DONG = 0,KHONG_KHOA = 0;
INT16 COUNT_50Hz;
INT8 COUNT_LIMIT;
#int_TIMER2
void TIMER2_isr(void)

{
COUNT_50HZ++;
if (COUNT_50HZ >= 200) // 200*0,1=20ms (xung 50Hz)
{
COUNT_LIMIT = COUNT_LIMIT +1;
COUNT_50HZ =0;
OUTPUT_HIGH(SERVO);
}
if (COUNT_50HZ >= ON_DUTY)OUTPUT_LOW(SERVO);
}
void main()
{
INT8 MENU,I,K,V;
INT8 TEMP[5];
port_b_pullups (0B11100000);
START_UP();
LOAD_DATA();
LCD_PUTC('\f');
DOOR_CLOSE();
WHILE(TRUE) //
{
IF(BAO_DONG)
{
LCD_GOTOXY(1,2);
LCD_PUTC("CO DOT NHAP ");
BEEP_BUZZ(1);
DELAY_MS(300);
}

LCD_GOTOXY(1,1);
IF(INPUT(SENSOR)== 0)//SENSOR CUA DONG
{
IF(KHONG_KHOA == 0){
LCD_PUTC("Cua da dong! ");LCD_GOTOXY(1,2);LCD_PUTC("Ban khoa khong ? ");
WHILE (INPUT(SENSOR)== 0)
{
IF(PRESS(BUT_ENT,1))
{ KHONG_KHOA = 0;
KHOA = 1;
DOOR_CLOSE();BEEP_BUZZ(1); LCD_PUTC('\f');LCD_GOTOXY(1,2);LCD_PUTC("Cua dong va khoa");
KHONG_KHOA =1;BREAK;}// DE DONG CHOT KHOA CUA
IF(PRESS(BUT_CAN,1))
{
KHONG_KHOA = 1;
KHOA = 0;
LCD_PUTC('\f');
BEEP_BUZZ(3);LCD_GOTOXY(1,2);
LCD_PUTC("Cua khong khoa ");
BREAK;
}
DELAY_MS(100);
}
}
}
ELSE //CUA MO
{
LCD_PUTC('\f');
LCD_GOTOXY(1,2);
IF(KHOA == 1)//DANG KHOA MA CUA MO
{
BAO_DONG = 1;
}
ELSE {LCD_PUTC("Cua dang mo! ");KHONG_KHOA = 0;}

}
// xet cam bien cua co dong hay chua. neu chua thi bao cua dang mo
// CONTROL_SERVO();
// DELAY_MS(100);
// CONTROL_SERVO();
//DELAY_MS(1000);
// IF(PRESS(BUT_UP,0))ON_DUTY = ON_DUTY +1;
// IF(PRESS(BUT_DOW,0))ON_DUTY = ON_DUTY -1;
// PRINTF(LCD_PUTC,"%lD ",ON_DUTY);

if(read_4102(TEMP))
{
BEEP_BUZZ(3);
for (I = 0;I < 5 ; I++)TEMP[I] = xoay(TEMP[I]);
TAGNUM = MAKE32(TEMP[1],TEMP[2],TEMP[3],TEMP[4]);
// CONVERT_ID(TAGNUM);
// LCD_GOTOXY(1,1);
// PRINTF(LCD_PUTC,"%LD ",TAGNUM);
// FOR(I=0;I<10;I++)LCD_PUTC(DECIMAL[I]+48);
// LCD_GOTOXY(9,1);
K = SEACH_ID(ID,TAGNUM);
// PRINTF(LCD_PUTC,"%D ",K);
IF(K<50)
{
DOOR_OPEN();
KHOA =0;
BAO_DONG = 0;
LCD_GOTOXY(1,1);
LCD_PUTC("Khoa da mo ");
LCD_GOTOXY(1,2);
LCD_PUTC("Moi ");
FOR(V=5;V<12;V++)LCD_PUTC(STORE_ID[K][V]);// HIEN THI TEN CUA THE DA QUET;
LCD_PUTC("...! ");
DELAY_MS(4000);
}

ELSE {LCD_PUTC("\f"); LCD_GOTOXY(1,2);LCD_PUTC("The khong hop le "); DELAY_MS(1000);LCD_PUTC('\f');}
}
OUTPUT_HIGH(LED);
DELAY_MS(100);
OUTPUT_LOW(LED);
DELAY_MS(100);

IF(PRESS(BUT_MOD,1))// NHAN MOD DE CAI DAT HE THONG
{
LCD_PUTC("\f");
IF(ENTER_PASS() == 1)
{
MENU = CAI_DAT();
IF (MENU == 1) {DOOR_OPEN();BAO_DONG = 0; KHOA =0;}
IF (MENU == 2) WHILE( ADD_TAG()==1)DELAY_MS(100);
IF (MENU == 3) WHILE(DEL_TAG()==1)DELAY_MS(100);
IF (MENU == 4) WHILE(CHANGE_PASS()==1)DELAY_MS(100);
LOAD_DATA();
}
}
DELAY_MS(30);//
}

}

Xin chân thành cảm ơn!
chauphuoc vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 19-04-2014, 08:07 PM   #7
thienduyen3
Nhập môn đệ tử
 
Tham gia ngày: Sep 2013
Bài gửi: 2
:
loi mplab

các bạn cho mình hỏi là sau khi mình viết code xong, xuất file hex trong mplab ide v8.91 thì hiện lên thông báo như thế này. Làm sao để khắc phục sự cố này mong các bạn giúp đỡ, thank all
Hình Ðính Kèm
Click image for larger version

Name:	Untitled.png
Views:	115
Size:	243.3 KB
ID:	5887  

thienduyen3 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 21-04-2014, 01:32 PM   #8
thaithinh
Nhập môn đệ tử
 
Tham gia ngày: Apr 2014
Bài gửi: 2
:
các anh chị ơi! hiện tại em đang làm về đèn giao thông dùng pic 16f877a và ccs, em đã xây dựng được code đơn giản rồi nhưng vấn đề là em muốn có thêm led 7 vạch chạy thời gian mà chưa biết làm sao, mong được chỉ giáo ạh!
#include<16f877A.h>
#device *=16 ADC=8
#fuses NOWDT,HS,NOPUT,NOPROTECT,NODEBUG,NOBROWNOUT,NOLVP, NOCPD,NOWRT
#use delay(clock=20000000)
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7, bits=9)
#include<def_877a.h>
int8 dem;
void main()
{
trisb=0;

dem==0;
while(1)
{
rb0=1;rb1=0;rb2=0;
rb3=0;rb4=0;rb5=1;
for(dem=0;dem<=35;dem++);
{
delay_ms(1000);
}



rb0=0;rb1=1;rb2=0;
rb3=0;rb4=0;rb5=1;
for(dem=0;dem<=5;dem++);
{
delay_ms(1000);
}



rb0=0;rb1=0;rb2=1;
rb3=1;rb4=0;rb5=0;
for(dem=0;dem<=35;dem++);
{
delay_ms(1000);
}




rb0=0;rb1=0;rb2=1;
rb3=0;rb4=1;rb5=0;
for(dem=0;dem<=5;dem++)
{
delay_ms(1000);
}
}
}
xin gửi vào mail cho em nhé! thaithinh_9x@yahoo.com.vn
thaithinh vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 19-06-2015, 10:29 AM   #9
codon_557
Nhập môn đệ tử
 
Tham gia ngày: Jun 2015
Bài gửi: 1
:
Smile sử dụng PWM để điều khiển bóng đèn dùng Pic16f887 & CCS

chào mọi người,
mình đang tìm hiểu về đèn led 3 màu, để điều khiển độ sáng tối của bóng đèn sử dụng PWM, mọi người có code mẫu nào post lên cho mình và các bạn khác có cùng ý tưởng tham khảo với nhé,hay có luồng tài liệu nào thì cho mình đường link với?mình đang học hỏi làm quảng cáo, mong mọi người giúp đỡ.
cảm ơn nhiều!
codon_557 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 01-10-2015, 10:33 AM   #10
tuan43
Nhập môn đệ tử
 
Tham gia ngày: Oct 2015
Bài gửi: 2
:
Bạn vào đường linh này để tham khảo: denled.com/product/đèn-led-dây-5050-nháy-3-màu/
tuan43 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 01-10-2015, 10:41 AM   #11
tuan43
Nhập môn đệ tử
 
Tham gia ngày: Oct 2015
Bài gửi: 2
:
Mình đang muốn làm mạch in trong proteus. Nhưng không biết mua phần mềm proteus ở đâu ,rất mong các bạn giúp đỡ
tuan43 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 31-10-2015, 04:58 PM   #12
thainguyenduong
Nhập môn đệ tử
 
Tham gia ngày: Apr 2015
Bài gửi: 1
:
cảm biến MLX90614 đo nhiệt độ non_contact.

mình đang đọc dữ liệu từ con cảm biến MLX90614 bằng PIC18F4620 bằng SMBUS, tuy nhiên bị lỗi khi đọc về toàn là 0xFFFF, ai có biết và kinh nghiệm về phần này có thể cho mình vài tham khảo được không.
đây là code của mình

void I2C1_init(void) // init I2C1 as master
{
TRISCbits.TRISC3 = 1; // LT4100 SCK, Smart battery SCK
TRISCbits.TRISC4 = 1; // LT4100 SDA, Smart battery SDA
//PIE1bits.SSPIE = 1;
SSPCON1 = 0x28; //enable serial port and configure SDA and SCL
SSPSTATbits.SMP = 0; //slew rate disable and configered to input level to I2C (< 100k)
SSPSTATbits.CKE = 1; // Enable input logic thresholds to SMBus compatable
SSPADD = 49; // baud rate fixed to
SSPCON2 = 0x00;
//SSPCON2bits.ACKEN = 1;
}

void I2C1_Idle(void)
{
//while (SSP1STATbits.BF); // Wait for bus Idle (BF - is high while transmission in progress)
while ((SSPCON2 & 0x1F) | (SSPSTATbits.R_W));
}
void I2C1SSPIFWait(void)
{
while (PIR1bits.SSPIF != 1);
PIR1bits.SSPIF = 0;
}
void I2C1_start(void)
{
I2C1_Idle(); // Wait for Bus Idle

SSPCON2bits.SEN = 1;
I2C1SSPIFWait();
}
void I2C1_repeated_start(void)
{
SSPCON2bits.RSEN = 1;
I2C1SSPIFWait();
}
void I2C1_stop(void)
{
SSPCON2bits.PEN = 1; // STOP condition
I2C1SSPIFWait();
}

void I2C1Ack(void)
{
SSPCON2bits.ACKDT = 0; /* Acknowledge data bit, 0 = ACK */
SSPCON2bits.ACKEN = 1; /* Ack data enabled */
while(SSPCON2bits.ACKEN); /* wait for ack data to send on bus */
}

void I2C1Nak(void)
{
SSPCON2bits.ACKDT = 1; /* Acknowledge data bit, 1 = NAK */
SSPCON2bits.ACKEN = 1; /* Ack data enabled */
while(SSPCON2bits.ACKEN); /* wait for ack data to send on bus */
}
void I2C1RecieveEnable(void)
{
SSPCON2bits.RCEN = 1; //enable receive enable bit
I2C1SSPIFWait();
}
//address msb bits. LSB read/write 1/0 bit
void I2C1_byte_write(unsigned char dev_add, unsigned char loc_add, unsigned char loc_dat)
{
I2C1_start(); // SMBus START
SSPBUF = dev_add; // temp_add;//device add + write
I2C1SSPIFWait();
SSPBUF = loc_add; // Storage Address (command)
I2C1SSPIFWait();
SSPBUF = loc_dat; // data
I2C1SSPIFWait();
I2C1_stop(); // SMBus STOP
}

void I2C1_word_write(unsigned char dev_add, unsigned char loc_add, unsigned int loc_dat)
{
unsigned char loc_dat_msb = 0, loc_dat_lsb = 0;
loc_dat_msb = ((loc_dat & 0xFF00) >> 8);
loc_dat_lsb = (loc_dat & 0x00FF);
I2C1_start(); // SMBus START
SSPBUF = dev_add; // device add + write bit
I2C1SSPIFWait();
SSPBUF = loc_add; // Storage Address (command)
I2C1SSPIFWait();
SSPBUF = loc_dat_lsb; // LSB data
I2C1SSPIFWait();
SSPBUF = loc_dat_msb; // MSB data
I2C1SSPIFWait();
I2C1_stop(); // SMBus STOP
}

unsigned char I2C1_byte_read(unsigned char dev_add, unsigned char loc_add)
{
unsigned char read_dat = 0;
unsigned char temp_add = (dev_add | 0x01);
I2C1_start(); // SMBus START
SSPBUF = dev_add; // Slave Address with Write Bit
I2C1SSPIFWait();
//pointing to specific location
SSPBUF = loc_add; //Command Code / add location
I2C1SSPIFWait();
//I2C1_repeated_start();
SSPBUF = temp_add; //Slave Address + Read Bit
I2C1SSPIFWait();

read_dat = SSPBUF; //saving data into some register
// SSPCON2bits.ACKDT = 0; // Send an ack bit
// SSPCON2bits.ACKEN = 1;
// while (SSPCON2bits.ACKEN); // Wait for ack to finish
I2C1_stop(); // SMBus STOP
return (read_dat);
}
unsigned int I2C1_Word_read(unsigned char dev_add, unsigned char loc_add)
{
unsigned int read_dat_msb = 0, read_dat_lsb = 0, read_dat = 0, read_dat_pec = 0;
unsigned char temp_add = (dev_add | 0x01); //((dev_add << 1) | 0x01); //Fz_Mod

I2C1_start(); // SMBus START
SSPBUF = dev_add; // Slave Address with Write Bit
I2C1SSPIFWait();

//pointing to specific location
SSPBUF = loc_add; //Command Code / add location
I2C1SSPIFWait();

I2C1_repeated_start(); // Repeated Start
SSPBUF = temp_add; //Slave Address + Read Bit
I2C1SSPIFWait();
I2C1RecieveEnable(); // Receive Enable


read_dat_lsb = SSPBUF; //saving data into some register


I2C1Ack(); // ACK
I2C1RecieveEnable(); // Receive Enable


read_dat_msb = SSPBUF; //saving data into some register


I2C1Nak(); // ACK
I2C1RecieveEnable(); // Receive Enable

read_dat_pec = SSPBUF;

//I2C1Ack(); // NACK
I2C1_stop(); // SMBus STOP

read_dat_msb = read_dat_msb << 8;
read_dat = read_dat_msb | read_dat_lsb;

return (read_dat);


}
thainguyenduong vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 11-11-2015, 11:14 PM   #13
huynhquynhtd
Nhập môn đệ tử
 
Tham gia ngày: Aug 2015
Bài gửi: 1
:
Exclamation pic 16f887

các bạn cho mình hỏi lỗi trong code này khắc phục thế nào z?
mình tìm được trên mạng nhưng khi buil lại có lỗi. mong các bạn giúp
hình lỗi nằm bên dưới!



#include <16F887.h>
#use delay(clock=20000000)

#include <LCD.c>
#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#use fast_io(d)
//==================khai bao ham con=============
int quetphim();
int checkphim(b);
void pwm();
void ghi_tocdo();
void ghi_thoigian();
void clear();
void read_rom();
//==================khai bao bien================
int8 i,t,a,b,c,d,sttphim,duty,ct,l,m;
int16 s_xung,s_vong,setpoint,error,luu,tg,tg1,dem;
//================ bien luu eeprom==============
int8 e0,e1,e2,e3,j,k;
int16 e;
//================chuong trinh quet phim==========
//quet phim so
int quetphim()
{
output_b(0xe0);// B4=0
a=0;
b=1;
checkphim(b);
if (a!=0)
{delay_ms(200);
return (sttphim);}
output_b(0xd0);// B5=0
a=0;
b=2;
checkphim(b);
if (a!=0)
{delay_ms(200);
return (sttphim);}
output_b(0xb0);// B6=0
a=0;
b=3;
checkphim(b);
if (a!=0)
{delay_ms(200);
return (sttphim);}
output_b(0x70);// B6=0
a=0;
b=4;
checkphim(b);
if (a!=0)
{delay_ms(200);
return (sttphim);}}

//============chuong trinh check phim=============
int checkphim(b)
{
switch (b)
{
case 1:
if(!input(pin_a0))
{sttphim=1;
a=1;}
else if(!input(pin_a1))
{sttphim=2;
a=1;}
else if(!input(pin_a2))
{sttphim=3;
a=1;}
else if(!input(pin_a3))
{ sttphim=10;//thuan
a=1;}
else {}
break;

case 2:
if(!input(pin_a0))
{sttphim=4;
a=1;}
else if(!input(pin_a1))
{sttphim=5;
a=1;}
else if(!input(pin_a2))
{sttphim=6;
a=1;}
else if(!input(pin_a3))
{sttphim=11;//nghich
a=1;}
else {}
break;
case 3:
if(!input(pin_a0))
{sttphim=7;
a=1;}
else if(!input(pin_a1))
{sttphim=8;
a=1;}
else if(!input(pin_a2))
{sttphim=9;
a=1;}
else if(!input(pin_a3))
{sttphim=12;//stop
a=1;}
else {}
break;

case 4:
if(!input(pin_a0))
{sttphim=0;//0
a=1;}
else if(!input(pin_a1))
{sttphim=15;//save
a=1;}
else if(!input(pin_a2))
{sttphim=14;//clear
a=1;}
else if(!input(pin_a3))
{sttphim=13;//set
a=1;}
else {}
break;}
return (sttphim);
}
// chuong trinh nhan xung tu encoder
//ngat ngoai, nhan xung tu encoder
#int_ext
void RB0_isr()
{
s_xung++;//dem so xung o chan RB0
}
//ngat timer1, tinh toan pwm va hien thi
#int_timer1
void timer1_isr()
{
set_timer1(-62500);
if (t==5){
S_vong=s_xung*2;//xung tren phut
//ht
lcd_gotoxy(1,1);
printf(lcd_putc," ");
if(ct==1)
{
lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=%lu v/p",luu);}
else {
lcd_gotoxy(1,1);
printf(lcd_putc,"TG_dat=%lu s",tg);}
lcd_gotoxy(1,2);
printf(lcd_putc," ");
if (d==2)
{lcd_gotoxy(1,2);
printf(lcd_putc,"TD_tt=-%luv/p",s_vong);}
if (d==1)
{lcd_gotoxy(1,2);
printf(lcd_putc,"TD_tt= %luv/p",s_vong);}
//=========================
//xuat pwm
pwm();
//========================
s_xung=0;
s_vong=0;
t=0;
set_timer1(-62500);
}
else
t++;
set_timer1(-62500);
}
//ngat timer0, dat thoi gian
#int_timer0
void time0_irs()
{
set_timer0(-235);
if (dem>=tg1)
{
output_high(pin_e0);
delay_us(100);
output_low(pin_e0);
dem=0;
if (d==1)
{d=2;}
else if (d==2)
{d=1;}
else{}
set_timer0(-235);
}
else {
dem++;
set_timer0(-235);}
}


void pwm()
{
if ((luu>s_vong)&& duty<250)
{error=luu-s_vong;
if (error>1000)
duty=duty+50;
else if (error>100)
duty=duty+20;
else if (error>30)
{duty=duty+5;}
else if (error>20)
duty=duty+1.5;
else if (error>10)
duty=duty+(0.05*error);
else {duty=duty+(0.025*error);}
}
if (luu<(s_vong-2)&& (duty>0))
{error=s_vong-luu;
if (error>=10)
duty=duty-(0.05*error);
else (duty=duty-(0.02*error));
}
if(luu==s_vong)
duty=duty;
if((duty>=250)&&(luu>s_vong))
{ lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc," TD_tt=MAX ");}
if (d==0)
{set_pwm1_duty(0);
set_pwm2_duty(0);}
else if (d==1)
{set_pwm1_duty(duty);
set_pwm2_duty(0);}
else
{set_pwm1_duty(0);
set_pwm2_duty(duty);}
}
//========chuong trinh con nhap toc do=======
void ghi_tocdo()
{
if(i>=0&&i<=3)
{
// giai thuat luu eeprom
if (i==0)
e0=sttphim;
else if (i==1)
e1=sttphim;
else if (i==2)
e2=sttphim;
else {e3=sttphim;}
//===============================
setpoint*=10;
setpoint+=sttphim;
i++;
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=%lu v/p",setpoint);
luu=setpoint;
}
else {
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"0<TD_dat<=9999");
delay_ms(1000);
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=%lu s",setpoint);
}}
//=========chuong trình con nhap thoi gian=========
void ghi_thoigian()
{
if(l>=0&&l<=3)
{
tg*=10;
tg+=sttphim;
l++;
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc,"TG_dat=%lu s",tg);
tg1=tg/0.12;
}
else {
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," 0<TG_dat<=999 ");
delay_ms(1000);
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc,"TG_dat=%lu s",tg);
}}
//============chuong trinh con clear=========
void clear()
{
setpoint=0;
tg=0;
i=0;l=0;m=0;
e0=0;e1=0;e2=0;e3=0;
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=_");
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc,"TG_dat=_");
}
//=======chuong trinh con luu toc do vao epprom======
void read_rom()
{
k=read_eeprom(4);
for (j=0;j<k;j++)
{
e=e*10;
e=e+read_eeprom(j);
}}



//chuong trinh chinh
void main()
{
i=0;
sttphim=0;
setpoint=0;tg=0;
duty=0;
c=0;
d=0;
ct=0;l=0;m=0;
e0=0;e1=0;e2=0;e3=0;e=0;k=0;
//================================================== ==========
//1:ngo vao;0: la ngo ra
set_tris_b(0b00001111);//4 chan RB4-RB7 xuat du lieu ra ban phim
set_tris_a(0b00001111);//4 chan RA0-RA3 nhan du lieu tu ban phim
set_tris_c(0b00000000);//2 chan RC0 va RC1 xuat PWM
set_tris_D(0b00000000);//port D la port xuat du lieu ra LCD
//================================================== ==========
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
/* timer1 la bo dinh thoi su dung xung noi,bo chia 1:8 thay doi moi 1600ns
Dung timer1 de ngat moi 0.1s do vay ta dat gia tri cho timer1 la :
0.1s/1600ns=62500(D)=F424(H) =>gia tri nap la FFFF-F424=BDB*/
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
enable_interrupts(int_ext);//khoi dong ngat ngoai
ext_int_edge(H_TO_L); // xung tu cao xuong thap
enable_interrupts(global);// khoi dong bit ngat GIE
setup_timer_2(T2_DIV_BY_4,249,1);
/*timer2 dung dinh thoi cho bo PWM
mode: bo chia thoi gian (prescale) cua timer2 1:4
period: gia tri nap chi thanh ghi PR2
postscale : bo chi ra,chon 1:1 PWM khong dung
Thach anh 20MHz, PWM fre: 10000Hz, thay doi duty cycle(%) de thay doi toc do*/
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
set_pwm1_duty(0);
set_pwm2_duty(0);
//================================================== =========
lcd_init();
lcd_send_byte(0,0x01);
lcd_gotoxy(1,1);
printf(lcd_putc,"CHUONG TRINH DK ");
lcd_gotoxy(1,2);
printf(lcd_putc," TD DONG CO DC ");
delay_ms(100);
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," ");
read_rom();
lcd_gotoxy(1,1);
printf(lcd_putc,"CHON CHE DO :_ ");
while (true)
{
while (c==0)
{
quetphim();
if (a!=0)
{
if (sttphim==1)
{ ct=1;
c=1;
lcd_gotoxy(1,1);
printf(lcd_putc,"CHON CHE DO :_%u",ct);}
if (sttphim==2)
{ ct=2;
c=1;
lcd_gotoxy(1,1);
printf(lcd_putc,"CHON CHE DO :_%u",ct);}
}
}
if (ct==1)
{lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=_ v/p");
lcd_gotoxy(1,2);
printf(lcd_putc,"TD_luu=%lu v/p",e);}
else {
lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=_ v/p");
lcd_gotoxy(1,2);
printf(lcd_putc,"TG_dat=_ s");}
While (c==1)
{
quetphim();

if (a!=0)
{
if (sttphim>=0 && sttphim<=9)//ban phim tu 0--->9
{
if (m==0)
{ghi_tocdo();}
if((ct==2)&&(m==1))
{ghi_thoigian();}
}
if (sttphim==14)
{clear();}
if ((sttphim==13)&&(i==0)&&(e==0))
{
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"Phai nhap TD_dat");
delay_ms(100);
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"TD_dat=_");
}
if ((sttphim==15)&&(i!=0)) //luu vao eeprom
{
write_eeprom(0,e0);
delay_ms(100);
write_eeprom(1,e1);
delay_ms(100);
write_eeprom(2,e2);
delay_ms(100);
write_eeprom(3,e3);
delay_ms(100);
write_eeprom(4,i);
delay_ms(100);
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," LUU THANH CONG ");
}
if ((sttphim==13)&&((i!=0)||(e!=0)))
{
if (ct==1)
{
c=2;
if (e!=0 && i==0)
luu=e;}
if ((ct==2)&&(l>=2))
{
c=2;}
m=1;
}}}
while (c==2)
{
quetphim();
if(a!=0)
{
if(sttphim==10)
{
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," QUAY THUAN ");
if (ct==2)
{enable_interrupts(int_timer0);
set_timer1(-235);}
enable_interrupts(int_timer1);
enable_interrupts(global);
set_timer1(-62500);
set_pwm1_duty(duty);
d=1;
}
if (sttphim==11)
{
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," QUAY NGHICH ");
if (ct==2)
{enable_interrupts(int_timer0);
set_timer1(-235);}
enable_interrupts(int_timer1);
enable_interrupts(global);
set_timer1(-62500);
set_pwm2_duty(duty);
d=2;
}
if (sttphim==12)//stop
{
disable_interrupts(int_timer0);
set_timer0(0);
disable_interrupts(int_timer1);
set_pwm1_duty(0);
set_pwm2_duty(0);
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," STOP ");
duty=0;
d=0;
}
if (sttphim==14)
{
clear();
c=0;
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"CHON CHE DO :_ ");
}}}}}
Hình Kèm Theo
File Type: jpg 12242733_1495541040741259_251534298_o.jpg (117.2 KB, 74 lần tải)
huynhquynhtd vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 08-12-2015, 09:38 PM   #14
saubeo6600
Nhập môn đệ tử
 
Tham gia ngày: Jun 2009
Bài gửi: 1
:
Huong Dan code pic 16f877a

Mình là dân tay ngang nhưng đam mê điện tử, mình mới tìm hiểu lập trình pic một thời gian, nhưng chưa đủ trình độ để hiểu chương trình này, xin mọi người giúp đỡ giải thích những dòng lệnh dưới đây, hoặc trong file đính kèm.Xin cám ơn rất nhiều. Mình có một ý tưởng để giúp đỡ ba mẹ đỡ nhọc nhằn, chỉ cần hiểu được code này mình tin sẽ lam được!

#include <16F877A.h>
#include <def_877a.h>
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=20000000)
int1 gt1, gt2, gt3, gt4;
char num=0,val=0;
char read_BCD()
{
if(input(PIN_A0))val |= 0x01;
if(input(PIN_A1))val |= 0x02;
if(input(PIN_A2))val |= 0x04;
if(input(PIN_A3))val |= 0x08;
return(val);
}
void kiemtra1()
{
gt1 = INPUT(pin_c0);
if(gt1==1)
{
output_high(pin_d0);
delay_ms(200);
output_low(pin_d0);
delay_ms(50);
output_high(pin_d0);
delay_ms(100);
output_low(pin_d0);}
if(gt1==0)
{
output_high(pin_d0);
delay_ms(200);
output_low(pin_d0);
delay_ms(50);}
}
void kiemtra2()
{
gt2 = INPUT(pin_c1);
if(gt2==1)
{
output_high(pin_d0);
delay_ms(100);
output_low(pin_d0);
delay_ms(50);
output_high(pin_d0);
delay_ms(100);
output_low(pin_d0);
}
if(gt2==0)
{
output_high(pin_d0)
;delay_ms(100);
output_low(pin_d0);
delay_ms(50);
}
}
void kiemtra3()
{
gt3 = INPUT(pin_c2);
if(gt3==1)
{ output_high(pin_d0);
delay_ms(100);
output_low(pin_d0);
delay_ms(50);
output_high(pin_d0);
delay_ms(100);
output_low(pin_d0);}
if(gt3==0)
{
output_high(pin_d0);
delay_ms(100);
output_low(pin_d0);
delay_ms(50);
}
}
void kiemtra4()
{
gt4 = INPUT(pin_c3);
if(gt4==1)
{
output_high(pin_d0);
delay_ms(100);
output_low(pin_d0);
delay_ms(50);
output_high(pin_d0);
delay_ms(100);
output_low(pin_d0);
}
if(gt4==0)
{
output_high(pin_d0);
delay_ms(100);
output_low(pin_d0);
delay_ms(50);}
}
void main()
{
int1 m=1;
set_tris_a(0xFF);
set_tris_c(0xff);
set_tris_d(0x00);
set_tris_b(0b00000001);
output_b(0x00);
output_d(0x00);
while(true)
{
if((input(PIN_B0))&&(m==1))
{
num=read_BCD();
val=0;m=0;
}
if((input(PIN_B0))==0)m=1;
switch(num)
{
case 0:break;
case 1:
{
output_toggle(PIN_B1);
num=0;
break;
}
case 2:
{
output_toggle(PIN_B2);
num=0;
break;
}
case 3:
{
output_toggle(PIN_B3);
num=0;
break;
}
case 4:
{
output_toggle(PIN_B4);
num=0;
break;
}
case 5:
{
kiemtra1();
num=0;
break;
}
case 6:
{
kiemtra2();
num=0;
break;
}
case 7:
{
kiemtra3();
num=0;
break;
}
case 8:
{
kiemtra4();
num=0;
break;
}

}}}
File Kèm Theo
File Type: zip dtmf.zip (728 Bytes, 144 lần tải)
saubeo6600 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à 12:23 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