Lớp VL Điện Tử 2009A-ĐH KHTN-TPHCM


 
Trang ChínhTrang Chính  GalleryGallery  Tìm kiếmTìm kiếm  Latest imagesLatest images  Đăng kýĐăng ký  Đăng Nhập  
.)..
Bài gởiNgười gởiThờii gian
Đề tài Tốt Nghiệp Code lm35 truyền lên giao diện máy tính AtomTue Dec 11, 2012 1:49 pm
[ TỔNG HỢP]BÀI GIẢNG ROBOT VÀ ĐIỀU KHIỂN Code lm35 truyền lên giao diện máy tính AtomTue Nov 27, 2012 2:32 pm
CODE THÂY NHAN TONG HOP Code lm35 truyền lên giao diện máy tính AtomThu Nov 15, 2012 2:37 pm
IC design Code lm35 truyền lên giao diện máy tính AtomWed Nov 14, 2012 10:08 pm
Chuẩn bị 20t11 Code lm35 truyền lên giao diện máy tính AtomTue Nov 13, 2012 5:41 pm
Mai (13/11/2012) nghỉ môn robot , đónng tiền và chuẩn bị 20/11 Code lm35 truyền lên giao diện máy tính AtomMon Nov 12, 2012 5:26 pm
Gửi bài môn PLC Code lm35 truyền lên giao diện máy tính AtomSat Nov 10, 2012 9:57 am
Đăng ký đề tài tốt nghiệp và điểm TB. Code lm35 truyền lên giao diện máy tính AtomMon Nov 05, 2012 5:41 pm
Thành lập nhóm nghiên cứu và phát triển tên lửa Tp.Hồ Chí Minh Code lm35 truyền lên giao diện máy tính AtomSun Nov 04, 2012 9:44 pm
TÀI LIỆU MÔN ROBOT NGÀY 23 THÁNG 10 Code lm35 truyền lên giao diện máy tính AtomTue Oct 23, 2012 8:03 pm
Thực hành thêm robot Code lm35 truyền lên giao diện máy tính AtomThu Oct 18, 2012 8:56 pm
IC Design_lab 2_bài 5 Code lm35 truyền lên giao diện máy tính AtomThu Oct 18, 2012 7:30 am

 

 Code lm35 truyền lên giao diện máy tính

Go down 
3 posters
Tác giảThông điệp
mrzero062




Tổng số bài gửi : 16
Join date : 18/09/2011

Code lm35 truyền lên giao diện máy tính Empty
Bài gửiTiêu đề: Code lm35 truyền lên giao diện máy tính   Code lm35 truyền lên giao diện máy tính EmptyWed May 30, 2012 7:42 pm

#include <mega32.h>
#include <stdlib.h>

#define RXB8 1
#define TXB8 0
#define UPE 2
#define OVR 3
#define FE 4
#define UDRE 5
#define RXC 7

#define FRAMING_ERROR (1<<FE)
#define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<OVR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)

// USART Receiver buffer
#define RX_BUFFER_SIZE 8
char rx_buffer[RX_BUFFER_SIZE];

#if RX_BUFFER_SIZE<256
unsigned char rx_wr_index,rx_rd_index,rx_counter;
#else
unsigned int rx_wr_index,rx_rd_index,rx_counter;
#endif

// This flag is set on USART Receiver buffer overflow
bit rx_buffer_overflow;

// USART Receiver interrupt service routine
interrupt [USART_RXC] void usart_rx_isr(void)
{
char status,data;
status=UCSRA;
data=UDR;
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
{
rx_buffer[rx_wr_index]=data;
if (++rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0;
if (++rx_counter == RX_BUFFER_SIZE)
{
rx_counter=0;
rx_buffer_overflow=1;
};
};
}

#ifndef _DEBUG_TERMINAL_IO_
// Get a character from the USART Receiver buffer
#define _ALTERNATE_GETCHAR_
#pragma used+
char getchar(void)
{
char data;
while (rx_counter==0);
data=rx_buffer[rx_rd_index];
if (++rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0;
#asm("cli")
--rx_counter;
#asm("sei")
return data;
}
#pragma used-
#endif

// USART Transmitter buffer
#define TX_BUFFER_SIZE 8
char tx_buffer[TX_BUFFER_SIZE];

#if TX_BUFFER_SIZE<256
unsigned char tx_wr_index,tx_rd_index,tx_counter;
#else
unsigned int tx_wr_index,tx_rd_index,tx_counter;
#endif

// USART Transmitter interrupt service routine
interrupt [USART_TXC] void usart_tx_isr(void)
{
if (tx_counter)
{
--tx_counter;
UDR=tx_buffer[tx_rd_index];
if (++tx_rd_index == TX_BUFFER_SIZE) tx_rd_index=0;
};
}

#ifndef _DEBUG_TERMINAL_IO_
// Write a character to the USART Transmitter buffer
#define _ALTERNATE_PUTCHAR_
#pragma used+
void putchar(char c)
{
while (tx_counter == TX_BUFFER_SIZE);
#asm("cli")
if (tx_counter || ((UCSRA & DATA_REGISTER_EMPTY)==0))
{
tx_buffer[tx_wr_index]=c;
if (++tx_wr_index == TX_BUFFER_SIZE) tx_wr_index=0;
++tx_counter;
}
else
UDR=c;
#asm("sei")
}
#pragma used-
#endif

// Standard Input/Output functions
#include <stdio.h>

#include <delay.h>

#define ADC_VREF_TYPE 0x60

// Read the 8 most significant bits
// of the AD conversion result
unsigned char read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCH;
}

// Declare your global variables here
unsigned char lm35,i,bientro,j;
float vin_lm35,t,tb_lm35,vin_bientro,r,tb_bientro;
char str_lm35[11],str_bientro[11];
void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0xD8;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x19;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// ADC initialization
// ADC Clock frequency: 1000.000 kHz
// ADC Voltage Reference: AVCC pin
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x82;
// Global enable interrupts
#asm("sei")

while (1)
{
// Place your code here
tb_lm35=0;
for(i=0;i<100;i++) //vong lap chong nhieu
{
lm35=read_adc(1); //doc ngo vao ADC
vin_lm35=(float)lm35*5/256; //doc dien ap ngo vao
t=vin_lm35*100; //tinh nhiet do
tb_lm35+=t;
}
t=tb_lm35/100;
ftoa(t,0,str_lm35); //chuyen nhiet do kieu float sang kieu chuoi
printf("%s",str_lm35); //truyen nhiet do len may tinh kieu chuoi
//putchar(str);
delay_ms(100);
// tb_bientro=0;
// for(j=0;j<100;j++) //vong lap chong nhieu
// {
// bientro=read_adc(0); //doc ngo vao ADC
// vin_bientro=(float)bientro*5; //doc dien ap ngo vao
// r=vin_bientro; //tinh nhiet do
// tb_bientro+=t;
// }
bientro = read_adc(0);
r=bientro/100;
ftoa(r,0,str_bientro); //chuyen nhiet do kieu float sang kieu chuoi
printf("%s",str_bientro); //truyen nhiet do len may tinh kieu chuoi
//putchar(str);
delay_ms(50);
};
}
Về Đầu Trang Go down
mrzero062




Tổng số bài gửi : 16
Join date : 18/09/2011

Code lm35 truyền lên giao diện máy tính Empty
Bài gửiTiêu đề: Re: Code lm35 truyền lên giao diện máy tính   Code lm35 truyền lên giao diện máy tính EmptyWed May 30, 2012 7:47 pm

Chọn thạch anh cho ATmega 4Mhz nha.
Về Đầu Trang Go down
minh_man




Tổng số bài gửi : 15
Join date : 18/05/2012

Code lm35 truyền lên giao diện máy tính Empty
Bài gửiTiêu đề: Re: Code lm35 truyền lên giao diện máy tính   Code lm35 truyền lên giao diện máy tính EmptyFri Jun 01, 2012 5:35 pm



mrzero062 Đã TEXT trên VisualBasic chưa...

mình làm nhiều lần nhưng không thể in 1 chuỗi lên text box của giao diện..

Bạn help mình nhé.. cheers
Về Đầu Trang Go down
Admin
Admin
Admin
Admin


Tổng số bài gửi : 116
Join date : 06/09/2011
Age : 34
Đến từ : long an

Code lm35 truyền lên giao diện máy tính Empty
Bài gửiTiêu đề: Code lm35 truyền lên giao diện máy tính   Code lm35 truyền lên giao diện máy tính EmptySat Jun 02, 2012 1:06 am


khai báo usart trong codevision.
khai báo thư viên stdio.h

muốn truyên lên máy tinh dùng hàm printf :
vd
printf(" vat ly điện tử");
Về Đầu Trang Go down
http://09vlh1.wordpress.com
Sponsored content





Code lm35 truyền lên giao diện máy tính Empty
Bài gửiTiêu đề: Re: Code lm35 truyền lên giao diện máy tính   Code lm35 truyền lên giao diện máy tính Empty

Về Đầu Trang Go down
 
Code lm35 truyền lên giao diện máy tính
Về Đầu Trang 
Trang 1 trong tổng số 1 trang
 Similar topics
-
» UP báo cáo chuyên đề !!!!!
» Thông báo về buổi nói chuyện chuyên đề "Tình yêu và sức khỏe giới tính" dành cho SV
» Cảm biến nhiệt độ LM35
» ORcad 16.0 hướng dẩn cài đặt & crack
» Quy định Về Bài Viết Trong Diễn Đàn

Permissions in this forum:Bạn không có quyền trả lời bài viết
Lớp VL Điện Tử 2009A-ĐH KHTN-TPHCM :: Thông báo lớp-
Chuyển đến 

Copyright © 2011, Lớp Vật Lý Điện tử 2009A-Khoa Vật lý-VLKT-Trường ĐH KHTN-TPHCM.Cảm ơn bạn đã tham gia diễn đàn
Xem tốt nhất trên các trình duyệt FireFox hoặc Google Chrome ở độ phân giải 1024 x 768 pixels.
Diễn đàn là một hệ thống mở, chúng tôi sẽ không chịu trách nhiệm về nội dung đăng tải do người dùng đưa lên.
Free forum | ©phpBB | Free forum support | Báo cáo lạm dụng | Thảo luận mới nhất