View Single Post
Old 14-07-2011, 11:33 AM   #2
thanhtb_89
Đệ tử 2 túi
 
Tham gia ngày: Jan 2011
Bài gửi: 37
:
đây là code của em viết.các bác xem giúp em nhé

================================================== =================
#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 0b00001000 //du lieu hien tren 4 led 7 thanh
//#define led_2 0b00000100
//#define led_3 0b00000010
//#define led_4 0b00000001

#define hien_thi_led_1 0b11110111
#define hien_thi_led_2 0b11111011
#define hien_thi_led_3 0b11111101
#define hien_thi_led_4 0b11111110

#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]

const unsigned char hien_thi_led[] ={hien_thi_led_1,hien_thi_led_2,hien_thi_led_3,hie n_thi_led_4};
//const unsigned char led[]={led_1,led_2,led_3,led_4};

char value;


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

//#int_RTCC
//void RTCC_isr(void)
//{void HIENTHI(); }

//===================================
//chuong trinh doc adc
//===================================
void main()
{
int8 value;
set_tris_A(1);
// init_board();
//===================================
//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();
value=500*value/1024;
//===================================
//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);
do
{
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();
delay_ms(20);
}
}while(n<4);
}
thanhtb_89 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn