Professional Documents
Culture Documents
VXL Code
VXL Code
h>
#include <delay.h>
#define LED PORTC
#define SW1 PINA.5
#define SW2 PINA.6
chuc=nhietdo/10;
dvi=nhietdo%10;
lcd_gotoxy(0,0);
lcd_puts("Nhiet do la: ");
lcd_gotoxy(0,1);
lcd_putchar(chuc+0x30); // 0x30 ma ASCII
lcd_putchar(dvi+0x30);
// VD:
// unsigned int nhietdo = read_adc(1)*500/1023;
// unsigned char chuc= (nhietdo%100)/10;
// unsigned char dvi= (nhietdo%10);
// lcd_gotoxy(0,0);
// lcd_puts ("nhiet do la: " );
// lcd_gotoxy(0,1);
// lcd_putchar(chuc+0x30);
// lcd_putchar(dvi+0x30);
// ADC + LCD
// ADC_out=read_adc(0);
// dienap = ADC_out*5000/1023; //theo mV 5000 mV = 5V
// nhietdo=dienap/10;
//
// chuc=nhietdo/10;
// dvi=nhietdo%10;
//
// lcd_gotoxy(0,0);
// lcd_puts("Nhiet do la: ");
// lcd_gotoxy(0,1);
// lcd_putchar(chuc+0x30); // 0x30 ma ASCII
// lcd_putchar(dvi+0x30);
// VD:
// unsigned int nhietdo = read_adc(1)*500/1023;
// unsigned char chuc= (nhietdo%100)/10;
// unsigned char dvi= (nhietdo%10);
// lcd_gotoxy(0,0);
// lcd_puts ("nhiet do la: " );
// lcd_gotoxy(0,1);
// lcd_putchar(chuc+0x30);
// lcd_putchar(dvi+0x30);
//
/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.0 Professional
Automatic Program Generator
© Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project : CUOI KI VI XU LY
Version :
Date : 18/12/2023
Author : TRAN MINH THUONG
Company :
Comments:
#include <mega16.h>
#include <string.h>
#include <delay.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#ifndef RXB8
#define RXB8 1
#endif
#ifndef TXB8
#define TXB8 0
#endif
#ifndef UPE
#define UPE 2
#endif
#ifndef DOR
#define DOR 3
#endif
#ifndef FE
#define FE 4
#endif
#ifndef UDRE
#define UDRE 5
#endif
#ifndef RXC
#define RXC 7
#endif
bit rx_buffer_overflow;
switch (data)
{
case '1':
PORTB.0 = 1; // Turn on the LED
break;
case '2':
PORTB.1 = 1; // Turn on the LED
break;
case '3':
PORTB.2 = 1; // Turn on the LED
break;
case '4':
PORTB.3 = 1; // Turn on the LED
break;
case '5':
PORTB.4 = 1; // Turn on the LED
break;
case '6':
PORTB.5 = 1; // Turn on the LED
break;
case '7':
PORTB.6 = 1; // Turn on the LED
break;
case '8':
PORTB.7 = 1; // Turn on the LED
break;
// tat den
case 'a':
PORTB.0 = 0; // Turn off the LED
break;
case 'b':
PORTB.1 = 0; // Turn off the LED
break;
case 'c':
PORTB.2 = 0; // Turn off the LED
break;
case 'd':
PORTB.3 = 0; // Turn off the LED
break;
case 'e':
PORTB.4 = 0; // Turn off the LED
break;
case 'f':
PORTB.5 = 0; // Turn off the LED
break;
case 'g':
PORTB.6 = 0; // Turn off the LED
break;
case 'h':
PORTB.7 = 0; // Turn off the LED
break;
// Add more cases if needed
default:
// Handle other characters if needed
break;
}
rx_buffer[rx_wr_index++] = data;
#if RX_BUFFER_SIZE == 256
// special case for receiver buffer size=256
if (++rx_counter == 0)
{
#else
if (rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0;
if (++rx_counter == RX_BUFFER_SIZE)
{
rx_counter=0;
#endif
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_BUFFER_SIZE != 256
if (rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0;
#endif
#asm("cli")
--rx_counter;
#asm("sei")
return data;
}
#pragma used-
#endif
#include <stdio.h>
// doc ADC
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
delay_us(10);
ADCSRA|=0x40;
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
unsigned int i=0;
unsigned long dienap;
unsigned long ADC_out=0;
unsigned long nhietdo;
unsigned char chuc, dvi;
void main(void)
{
bit ledState = 0;
// 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;
// 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=0xff;
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In
Func0=Out
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=0
PORTC=0x00;
DDRC=0x01;
// 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=0x02;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 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: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=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=0x98;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;
// ADC initialization
// ADC Clock frequency: 1000.000 kHz
// ADC Voltage Reference: AREF pin
// ADC Auto Trigger Source: ADC Stopped
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x83;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
chuc=nhietdo/10;
dvi=nhietdo%10;
//
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar;
using System.Reflection;
using System.Security.AccessControl;
namespace giaodien
{
public partial class Code : Form
{
private int counter = 0;
private bool isConnected = false;
public string temperature;
public double time_temperature;
public Code()
{
InitializeComponent();
}
string[] pause = { "1200", "2400", "4800", "9600", "19200", "38400",
"57600", "14880" };
private void Code_Load(object sender, EventArgs e)
{
string[] listnamecom = SerialPort.GetPortNames();
congcom.Items.AddRange(listnamecom);
baudrate.Items.AddRange(pause);
UpdateControls();
}
}
private void reset_Click(object sender, EventArgs e)
{
counter = 0;
hienthicounter.Text = counter.ToString();
}
private void UpdateControls()
{
ketnoi.Text = isConnected ? "DISCONNECT" : "CONNECT";
// ĐÈN
LED_1.Enabled = isConnected;
LED_2.Enabled = isConnected;
LED_3.Enabled = isConnected;
LED_4.Enabled = isConnected;
LED_5.Enabled = isConnected;
LED_6.Enabled = isConnected;
LED_7.Enabled = isConnected;
LED_8.Enabled = isConnected;
// counter
dem.Enabled = isConnected;
reset.Enabled = isConnected;
// chỉnh màu
if (isConnected)
{
// chua connect
LED_1.BackColor = Color.Black;
LED_2.BackColor = Color.Black;
LED_3.BackColor = Color.Black;
LED_4.BackColor = Color.Black;
LED_5.BackColor = Color.Black;
LED_6.BackColor = Color.Black;
LED_7.BackColor = Color.Black;
LED_8.BackColor = Color.Black;
}
else
{
// khi connect
LED_1.BackColor = SystemColors.Control;
LED_2.BackColor = SystemColors.Control;
LED_3.BackColor = SystemColors.Control;
LED_4.BackColor = SystemColors.Control;
LED_5.BackColor = SystemColors.Control;
LED_6.BackColor = SystemColors.Control;
LED_7.BackColor = SystemColors.Control;
LED_8.BackColor = SystemColors.Control;
}
}
private void serialPort1_DataReceived(object sender,
SerialDataReceivedEventArgs e)
{
temperature = serialPort1.ReadLine();
try
{
BeginInvoke(new Action(() =>
{
nhietdo.Text = temperature;
}));
}
catch (Exception)
{
MessageBox.Show("ERROR");
}
}
}
}