![]() |
|
![]() |
#1 |
Đệ tử 1 túi
Tham gia ngày: Jun 2011
Bài gửi: 18
: |
giao tiếp i2c PIC16f887 và TC74
Mong mọi người giúp em với ạ, chạy mô phỏng chỉ hiễn thị mỗi gia trị 255 thôi , không hiểu tại sao luôn hix, file mô phỏng em đính kèm dưới ạ
Code:
#include <htc.h> #include <stdio.h> #include "lcd.h" #include "i2c.h" __CONFIG(INTIO & WDTDIS & PWRTEN & MCLREN & UNPROTECT & DUNPROTECT & BORDIS & IESODIS & FCMDIS & LVPDIS); #define slave_add 0x90 #define write 0 #define read 1 void hienthilcd(unsigned int t) { char tr,ch,dv; tr=t/100; ch=(t-tr*100)/10; dv=t-tr*100-ch*10; lcd_gotoxy(5,1); lcd_putc(tr+0x30); lcd_gotoxy(6,1); lcd_putc(ch+0x30); lcd_gotoxy(7,1); lcd_putc(dv+0x30); } void read_temp() { unsigned int temp; //send start condition i2c_start(); //send slave add mode write i2c_write((slave_add<<1)|write); i2c_write(0x00); //send restart condition i2c_stop(); i2c_start(); //begin read i2c_write((slave_add<<1)|read); temp = i2c_read(0); i2c_stop(); __delay_ms(100); hienthilcd(temp); } void main() { unsigned int i; char t; lcd_init(); i2c_init(); while(1){ read_temp(); __delay_ms(100); } } |
![]() |
![]() |
![]() |
#2 |
Nhập môn đệ tử
Tham gia ngày: Dec 2014
Bài gửi: 1
: |
bạn chỉnh lại a0 cho tc74 tren mo phong thu coi
|
![]() |
![]() |
![]() |
#3 |
Nhập môn đệ tử
Tham gia ngày: Nov 2012
Bài gửi: 1
: |
chào các thánh. mình muốn hỏi 1 vấn đề ngoài luồng tý. Mình có lập trình đo ADC hiển thị LCD 2 dòng 16 ký tự, nhưng giá trị của ADC phải 20 phút sau mới hiển thị, khi thay đổi adc= biến trở cũng vậy hơn 20 phút sau nó mới thay đổi giá trị hiển thị trên màn hình LCD. trên proteus vẫn chạy bình thương mình ko thể khắc phục được mong các thánh giúp đỡ chút.
#include "Lcd_Main.h" #include "lcd.h" void main() { setup_adc_ports(sAN0|Vss_Vdd);// thiet lap chan ao lam chan nhân adc di?n ap tham chiêu vss-vdd setup_adc(adc_clock_internal);// xung lay mau = xung clock disable_interrupts(int_ad); setup_spi(SPI_SS_DISABLED); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); //Setup_Oscillator parameter not selected from Intr Oscillator Config tab // TODO: USER CODE!! unsigned char str[20]; unsigned int16 Value; LCD_Init(); sprintf(str," DEMO ADC"); delay_ms(10); LCD_Puts(str); delay_ms(1000); LCD_Clear(); while(TRUE) { set_adc_channel(0);//kenh doc adc delay_us(20); Value=read_adc(adc_start_and_read); LCD_Gotoxy(0,1); sprintf(str,"Gia Tri: %4lu",Value); LCD_Puts(str); delay_ms(1000); } trên đây là code của e. do lần đầu sử dụng diễn đàn mong các thánh thông cảm và giúp đỡ nhiều |
![]() |
![]() |
![]() |
|
|