PIC Vietnam

Go Back   PIC Vietnam > Các Đề Tài > PIC Việt Nam - Chuyên nghiệp

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 Việt Nam - Chuyên nghiệp Chúng ta sẽ thảo luận ở đây nhưng vấn đề về phương pháp nghiên cứu, cách làm việc và tổ chức công việc...

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 12-07-2011, 05:29 PM   #1
thanhtb_89
Đệ tử 2 túi
 
Tham gia ngày: Jan 2011
Bài gửi: 37
:
hỏi về 16f886

em viết code cho ic pic 16f886 để đo nhiệt độ dùng cảm biến lm35 và hiển thị ra led 7 thanh qua 2 ic 74595.
đây là code của em
các anh xem giúp họ em
em nạp code vào mà ko hiển thị được
================================================== ================


#include <16F886.h>
#device adc=10

#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPUT //No Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES PROTECT //Code not protected from reading
#FUSES NOCPD //No EE protection
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOIESO //No Internal External Switch Over mode enabled
#FUSES NOFCMEN //No Fail-safe clock monitor enabled
#FUSES NOLVP //No Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NODEBUG //No Debug mode for ICD
#FUSES WRT //Program memory write protected
#FUSES BORV40 //Brownout reset at 4v

#use delay(clock=4000000)


#byte PORTA = 0x05
#byte TRISA = 0x85

#byte PORTB = 0x06
#byte TRISB = 0x86

#byte PORTC = 0x07
#byte TRISC = 0x87

#byte ANSELL = 0x188
#byte ANSELH = 0x189
#byte ANSELL = 0x188

#byte SSPCON = 0x14
#byte SSPCON2 = 0x91
#byte SSPADD = 0x93
#byte SSPSTAT = 0x94

#byte SSPCON = 0x14
#byte SSPCON2 = 0x91
#byte SSPADD = 0x93
#byte SSPSTAT = 0x94

#byte PORTB = 0x06
#byte TRISB = 0x86
#bit rb5 = portb.5

//===================================
//define
//===================================


#define MASK_LED_0 0b00101000
#define MASK_LED_1 0b10101111
#define MASK_LED_2 0b10011000
#define MASK_LED_3 0b10001010
#define MASK_LED_4 0b00001111
#define MASK_LED_5 0b01001010
#define MASK_LED_6 0b01001000
#define MASK_LED_7 0b10101110
#define MASK_LED_8 0b00001000
#define MASK_LED_9 0b00001010

#define led_1 led[0] //du lieu hien tren 4 led 7 thanh
#define led_2 led[1]
#define led_3 led[2]
#define led_4 led[3]

#define hien_thi_led_1 0b00001000
#define hien_thi_led_2 0b00000010
#define hien_thi_led_3 0b00000100
#define hien_thi_led_4 0b00000001
const unsigned char hien_thi_led[] ={hien_thi_led_1,hien_thi_led_2,hien_thi_led_3,hie n_thi_led_4};
unsigned char led[8];


char value;


//===================================
//KHAI BAO CHUONG TRINH CON
//===================================
void HEX_BCD();
void HIENTHI();
void lat();


//===================================
//chuong trinh doc adc
//===================================
void main()
{
int8 value;
set_tris_A(1);

//===================================
//khoi tao che do cho ADC
//===================================

Setup_ADC(ADC_CLOCK_INTERNAL);//khoi tao ADC
setup_ADC_ports(sAN0|VSS_VDD);
Set_ADC_channel(0);
delay_us(10); //ket thuc khoi tao ADC

//===================================
//lay mau nhiet do cho lan dau tien
//===================================
while(true)
{
value=read_ADC();

//===================================
//chuong trinh hien thi
//===================================

HEX_BCD();
HIENTHI();
}
}

//================================================== ====================
//tach lay so hang tram, hang chuc, hang don vi de hien thi ra led
//================================================== ====================

void HEX_BCD()
{
int16 value;
led_1=value/1000;
value=value%1000;
led_2=value/100;
value=value%100;
led_3=value/10;
led_4=value%10;
}

//================================================== ====================
//chuong trinh latch
//================================================== ====================

void lat()
{
output_high(PIN_B3);
output_low(PIN_B3);

}

//================================================== ====================
//HIEN THI
//================================================== ====================
void HIENTHI()
{
unsigned char mask,i,n,k;
int1 data;
set_tris_B(0);
while(1)
{
for(n=4;n>=0;n--)
{
k=led[n];
for(i=8;i>=0;i--)
{
data = bit_test(k,n-1);
output_bit(pin_b5,data);
output_high(PIN_B4);
output_low(PIN_B4);

}
}


mask = hien_thi_led[n];
for(i=8;i>=0;i--)
{
data = bit_test(mask,i-1);
output_bit(pin_b5,data);
output_high(PIN_B4);
output_low(PIN_B4);
lat();
}

}
}
thanhtb_89 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 

Ð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à 05:45 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