Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

PROGRAM DAN DESAIN VISUAL BASIC

Private Sub Command1_Click(Index As Integer) Text1.Text = "*W010" & Index & "1#"
Text1.Text = "*W010" & Index & "1#" MSComm1.Output = Text1.Text
MSComm1.Output = Text1.Text
Shape1(Index).FillColor = vbRed End Sub
End Sub
Private Sub HScroll2_Change(Index As Integer)
Private Sub Command2_Click(Index As Integer) Text3.Text = HScroll2(Index).Value
Text1.Text = "*W010" & Index & "0#" If (Index = 1) Then
MSComm1.Output = Text1.Text Text3.Text = Format(HScroll2(Index).Value /
Shape1(Index).FillColor = vbBlack 10, "##.##")
End Sub End If
If Len(Text3.Text) = 3 Then
Private Sub Form_Load() Text3.Text = Text3.Text & 0
MSComm1.PortOpen = True End If
End Sub Text1.Text = "*W020" & Index & "1#"
MSComm1.Output = Text1.Text
Private Sub Form_UnLoad(cancel As Integer) End Sub
MSComm1.PortOpen = False
End Sub Private Sub HScroll3_Change(Index As Integer)
Text4.Text = HScroll3(Index).Value
Private Sub HScroll1_Change(Index As Integer) If (Index = 1) Then
Text2.Text = HScroll1(Index).Value Text4.Text = Format(HScroll3(Index).Value /
If (Index = 1) Then 10, "##.##")
Text2.Text = Format(HScroll1(Index).Value / End If
10, "##.##") If Len(Text4.Text) = 3 Then
End If Text4.Text = Text4.Text & 0
If Len(Text2.Text) = 3 Then End If
Text2.Text = Text2.Text & 0 Text1.Text = "*W030" & Index & "1#"
End If MSComm1.Output = Text1.Text
End Sub
Private Sub Command5_Click(Index As Integer)
Private Sub HScroll4_Change(Index As Integer) Text1.Text = "*W030" & Index & "1#"
Text5.Text = HScroll4(Index).Value MSComm1.Output = Text1.Text
If (Index = 1) Then Shape3(Index).FillColor = vbRed
Text5.Text = Format(HScroll4(Index).Value / End Sub
10, "##.##")
End If Private Sub Command6_Click(Index As Integer)
If Len(Text5.Text) = 3 Then Text1.Text = "*W030" & Index & "0#"
Text5.Text = Text5.Text & 0 MSComm1.Output = Text1.Text
End If Shape3(Index).FillColor = vbBlack
Text1.Text = "*W040" & Index & "1#" End Sub
MSComm1.Output = Text1.Text
Private Sub Command7_Click(Index As Integer)
End Sub Text1.Text = "*W040" & Index & "1#"
MSComm1.Output = Text1.Text
Shape4(Index).FillColor = vbRed
Private Sub MSComm1_OnComm() End Sub
Dim dataku As String
dataku = dataku & MSComm1.Input Private Sub Command8_Click(Index As Integer)
Text1.Text = dataku Text1.Text = "*W040" & Index & "0#"
End Sub MSComm1.Output = Text1.Text
Shape4(Index).FillColor = vbBlack
If Len(dataku) = 8 Then End Sub
Text1.Text = Mid(dataku, 3, 2)
Text1.Text = Mid(dataku, 5, 2)
Text1.Text = Mid(dataku, 7, 1) Private Sub Slider1_Click(Index As Integer)
Text6.Text = Slider1(Index).Value
If Val(Text1.Text = "1") Then If (Index = 1) Then
Shape1(Val(Text1.Text)).FillColor = vbRed Text6.Text = Format(Slider1(Index).Value / 10,
Shape2(Val(Text1.Text)).FillColor = vbRed "##.##")
Shape3(Val(Text1.Text)).FillColor = vbRed iThermometerX1(Index).Position = Text6.Text
Shape4(Val(Text1.Text)).FillColor = vbRed
Else End If
Shape1(Val(Text1.Text)).FillColor = vbBlack If Len(Text6.Text) = 3 Then
Shape2(Val(Text1.Text)).FillColor = vbBlack Text6.Text = Text6.Text & 0
Shape3(Val(Text1.Text)).FillColor = vbBlack End If
Shape4(Val(Text1.Text)).FillColor = vbBlack Text1.Text = "*W010" & Index & "1#"
End If MSComm1.Output = Text1.Text
End If End Sub
End Sub
Private Sub Slider2_Click(Index As Integer)
Text7.Text = Slider2(Index).Value
Private Sub Command3_Click(Index As Integer) If (Index = 1) Then
Text1.Text = "*W020" & Index & "1#" Text7.Text = Format(Slider2(Index).Value / 10,
MSComm1.Output = Text1.Text "##.##")
Shape2(Index).FillColor = vbRed iThermometerX1(Index).Position = Text7.Text
End Sub
End If
Private Sub Command4_Click(Index As Integer) If Len(Text7.Text) = 3 Then
Text1.Text = "*W020" & Index & "0#" Text7.Text = Text7.Text & 0
MSComm1.Output = Text1.Text End If
Shape2(Index).FillColor = vbBlack Text1.Text = "*W020" & Index & "1#"
End Sub MSComm1.Output = Text1.Text
End Sub

Private Sub Slider3_Click(Index As Integer)


Text8.Text = Slider3(Index).Value
If (Index = 1) Then
Text8.Text = Format(Slider3(Index).Value / 10,
"##.##")
iThermometerX1(Index).Position = Text8.Text

End If
If Len(Text8.Text) = 3 Then
Text8.Text = Text8.Text & 0
End If
Text1.Text = "*W013" & Index & "1#"
MSComm1.Output = Text1.Text
End Sub

Private Sub Slider4_Click(Index As Integer)


Text9.Text = Slider4(Index).Value
If (Index = 1) Then
Text9.Text = Format(Slider4(Index).Value / 10,
"##.##")
iThermometerX1(Index).Position = Text9.Text

End If
If Len(Text9.Text) = 3 Then
Text9.Text = Text9.Text & 0
End If
Text1.Text = "*W040" & Index & "1#"
MSComm1.Output = Text1.Text
End Sub

PROGRAM PADA MIKRO

#include <mega128.h> #ifndef DOR


#define DOR 3
// Alphanumeric LCD functions #endif
#include <alcd.h>
#include <stdlib.h> #ifndef FE
#include <stdio.h> #define FE 4
#endif
#ifndef RXB8
#define RXB8 1 #ifndef UDRE
#endif #define UDRE 5
#endif
#ifndef TXB8
#define TXB8 0 #ifndef RXC
#endif #define RXC 7
#endif
#ifndef UPE
#define UPE 2 #define FRAMING_ERROR (1<<FE)
#endif #define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<DOR)
#define DATA_REGISTER_EMPTY char data;
(1<<UDRE) while (rx_counter1==0);
#define RX_COMPLETE (1<<RXC) data=rx_buffer1[rx_rd_index1++];
#if RX_BUFFER_SIZE1 != 256
// USART1 Receiver buffer if (rx_rd_index1 == RX_BUFFER_SIZE1)
#define RX_BUFFER_SIZE1 24 rx_rd_index1=0;
char rx_buffer1[RX_BUFFER_SIZE1]; #endif
#asm("cli")
#if RX_BUFFER_SIZE1 <= 256 --rx_counter1;
unsigned char #asm("sei")
rx_wr_index1,rx_rd_index1,rx_counter1; return data;
#else }
unsigned int #pragma used-
rx_wr_index1,rx_rd_index1,rx_counter1; // Write a character to the USART1 Transmitter
#endif #pragma used+
void putchar1(char c)
// This flag is set on USART1 Receiver buffer {
overflow while ((UCSR1A &
bit rx_buffer_overflow1; DATA_REGISTER_EMPTY)==0);
UDR1=c;
// USART1 Receiver interrupt service routine }
interrupt [USART1_RXC] void #pragma used-
usart1_rx_isr(void)
{ // Declare your global variables here
char status,data;
status=UCSR1A; void main(void)
data=UDR1; {
if ((status & (FRAMING_ERROR | // Declare your local variables here
PARITY_ERROR | DATA_OVERRUN))==0) unsigned char mcu_add, data_add, ch;
{ unsigned char buff_data[10];
if(data=='*')rx_wr_index1=0;
rx_buffer1[rx_wr_index1]=data; // Input/Output Ports initialization
rx_wr_index1++; // Port A initialization
#if RX_BUFFER_SIZE1 == 256 // Func7=In Func6=In Func5=In Func4=In
// special case for receiver buffer size=256 Func3=In Func2=In Func1=In Func0=In
if (++rx_counter1 == 0) // State7=T State6=T State5=T State4=T
rx_buffer_overflow1=1; State3=T State2=T State1=T State0=T
#else PORTA=0x00;
if (rx_wr_index1 == RX_BUFFER_SIZE1) DDRA=0x00;
rx_wr_index1=0;
if (++rx_counter1 == RX_BUFFER_SIZE1) // Port B initialization
{ // Func7=In Func6=In Func5=In Func4=In
rx_counter1=0; Func3=In Func2=In Func1=In Func0=In
rx_buffer_overflow1=1; // State7=T State6=T State5=T State4=T
} State3=T State2=T State1=T State0=T
#endif PORTB=0x00;
} DDRB=0x00;
}
// Port C initialization
// Get a character from the USART1 Receiver // Func7=Out Func6=Out Func5=Out Func4=Out
buffer Func3=Out Func2=Out Func1=Out Func0=Out
#pragma used+ // State7=0 State6=0 State5=0 State4=0 State3=0
char getchar1(void) State2=0 State1=0 State0=0
{ PORTC=0x00;
DDRC=0xFF; // Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Port D initialization // Compare B Match Interrupt: Off
// Func7=In Func6=In Func5=In Func4=In // Compare C Match Interrupt: Off
Func3=In Func2=In Func1=In Func0=In TCCR1A=0x00;
// State7=T State6=T State5=T State4=T TCCR1B=0x00;
State3=T State2=T State1=T State0=T TCNT1H=0x00;
PORTD=0x00; TCNT1L=0x00;
DDRD=0x00; ICR1H=0x00;
ICR1L=0x00;
// Port E initialization OCR1AH=0x00;
// Func7=In Func6=In Func5=In Func4=In OCR1AL=0x00;
Func3=In Func2=In Func1=In Func0=In OCR1BH=0x00;
// State7=T State6=T State5=T State4=T OCR1BL=0x00;
State3=T State2=T State1=T State0=T OCR1CH=0x00;
PORTE=0x00; OCR1CL=0x00;
DDRE=0x00;
// Timer/Counter 2 initialization
// Port F initialization // Clock source: System Clock
// Func7=In Func6=In Func5=In Func4=In // Clock value: Timer2 Stopped
Func3=In Func2=In Func1=In Func0=In // Mode: Normal top=0xFF
// State7=T State6=T State5=T State4=T // OC2 output: Disconnected
State3=T State2=T State1=T State0=T TCCR2=0x00;
PORTF=0x00; TCNT2=0x00;
DDRF=0x00; OCR2=0x00;

// Port G initialization // Timer/Counter 3 initialization


// Func4=In Func3=In Func2=In Func1=In // Clock source: System Clock
Func0=In // Clock value: Timer3 Stopped
// State4=T State3=T State2=T State1=T // Mode: Normal top=0xFFFF
State0=T // OC3A output: Discon.
PORTG=0x00; // OC3B output: Discon.
DDRG=0x00; // OC3C output: Discon.
// Noise Canceler: Off
// Timer/Counter 0 initialization // Input Capture on Falling Edge
// Clock source: System Clock // Timer3 Overflow Interrupt: Off
// Clock value: Timer 0 Stopped // Input Capture Interrupt: Off
// Mode: Normal top=0xFF // Compare A Match Interrupt: Off
// OC0 output: Disconnected // Compare B Match Interrupt: Off
ASSR=0x00; // Compare C Match Interrupt: Off
TCCR0=0x00; TCCR3A=0x00;
TCNT0=0x00; TCCR3B=0x00;
OCR0=0x00; TCNT3H=0x00;
TCNT3L=0x00;
// Timer/Counter 1 initialization ICR3H=0x00;
// Clock source: System Clock ICR3L=0x00;
// Clock value: Timer1 Stopped OCR3AH=0x00;
// Mode: Normal top=0xFFFF OCR3AL=0x00;
// OC1A output: Discon. OCR3BH=0x00;
// OC1B output: Discon. OCR3BL=0x00;
// OC1C output: Discon. OCR3CH=0x00;
// Noise Canceler: Off OCR3CL=0x00;
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off // External Interrupt(s) initialization
// INT0: Off // Connections are specified in the
// INT1: Off // Project|Configure|C
// INT2: Off Compiler|Libraries|Alphanumeric LCD menu:
// INT3: Off // RS - PORTA Bit 0
// INT4: Off // RD - PORTA Bit 1
// INT5: Off // EN - PORTA Bit 2
// INT6: Off // D4 - PORTA Bit 4
// INT7: Off // D5 - PORTA Bit 5
EICRA=0x00; // D6 - PORTA Bit 6
EICRB=0x00; // D7 - PORTA Bit 7
EIMSK=0x00; // Characters/line: 20
lcd_init(20);
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00; // Global enable interrupts
#asm("sei")
ETIMSK=0x00;
mcu_add=3;
// USART0 initialization while (1)
// USART0 disabled {
UCSR0B=0x00; // Place your code here
lcd_gotoxy(0,0);
// USART1 initialization lcd_putchar(rx_buffer1[0]);
// Communication Parameters: 8 Data, 1 Stop, lcd_putchar(rx_buffer1[1]);
No Parity lcd_putchar(rx_buffer1[2]);
// USART1 Receiver: On lcd_putchar(rx_buffer1[3]);
// USART1 Transmitter: On lcd_putchar(rx_buffer1[4]);
// USART1 Mode: Asynchronous lcd_putchar(rx_buffer1[5]);
// USART1 Baud Rate: 9600 lcd_putchar(rx_buffer1[6]);
UCSR1A=0x00; lcd_putchar(rx_buffer1[7]);
UCSR1B=0x98; lcd_putchar(rx_buffer1[8]);
UCSR1C=0x06; if(rx_buffer1[0]=='*' && rx_buffer1[7]=='#')
UBRR1H=0x00; {
UBRR1L=0x33; if(rx_buffer1[1]=='w' || rx_buffer1[1]=='W')
{
// Analog Comparator initialization
// Analog Comparator: Off sprintf(buff_data,"%c%c",rx_buffer1[2],rx_buffe
// Analog Comparator Input Capture by r1[3]);
Timer/Counter 1: Off data_add=atoi(buff_data);
ACSR=0x80; if(data_add==mcu_add)
SFIOR=0x00; {

// ADC initialization sprintf(buff_data,"%c%c",rx_buffer1[4],rx_buffe


// ADC disabled r1[5]);
ADCSRA=0x00; ch=atoi(buff_data);
if(ch==0)
// SPI initialization {
// SPI disabled if(rx_buffer1[6]=='1') PORTC.1=1;
SPCR=0x00; else if(rx_buffer1[6]=='0') PORTC.1=0;
}
// TWI initialization else if(ch==1)
// TWI disabled {
TWCR=0x00; if(rx_buffer1[6]=='1') PORTC.3=1;
else if(rx_buffer1[6]=='0') PORTC.3=0;
// Alphanumeric LCD initialization }
else if(ch==2)
{
if(rx_buffer1[6]=='1') PORTC.5=1;
else if(rx_buffer1[6]=='0') PORTC.5=0;
}
else if(ch==3)
{
if(rx_buffer1[6]=='1') PORTC.7=1;
else if(rx_buffer1[6]=='0') PORTC.7=0;
}
rx_buffer1[7]=0;
}
}
}

}
}

You might also like