/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
© Copyright 1998-2011 PavelHaiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date
: 26-May-2016
Author :czr_
Company :
Comments:
Chip type
: ATmega32A
Program type
: Application
AVR Core Clock frequency: 11.059200 MHz
Memory model
: Small
External RAM size
: 0
Data Stack size
: 512
*****************************************************/
#include
#include
#include
#include
<mega32a.h>
<stdlib.h>
<stdio.h>
<delay.h>
eepromintval;
int i0,i1,i2,i;
char data[16];
floatgula_normal,gula_predia,gula_diabet;
// Alphanumeric LCD functions
#include <alcd.h>
#define ADC_VREF_TYPE 0x00
// Read the AD conversion result
unsignedintread_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 ADCW;
}
// Declare your global variables here
voidadc()
{
i0=read_adc(0);
i1=read_adc(1);
i2=read_adc(2);
}
voidlcd_adc()
{
lcd_gotoxy(0,0);
itoa(i0,data);
lcd_puts(data);
lcd_gotoxy(6,0);
itoa(i1,data);
lcd_puts(data);
lcd_gotoxy(0,1);
itoa(i2,data);
lcd_puts(data);
lcd_gotoxy(6,1);
itoa(val,data);
lcd_puts(data);
delay_ms(100);
lcd_clear();
}
void calculate()
{
//calculate:
while(1)
{
//lcd_gotoxy(10,0);lcd_putsf("DIABET");
if
(val<=45
&& PINB.0==0)
{lcd_gotoxy(10,0);lcd_putsf("NORMAL");lcd_gotoxy(9,1);lcd_puts
f("SESAAT");}
//44=128
else if (val>=46 &&val<=50
&& PINB.0==0)
{lcd_gotoxy(10,0);lcd_putsf("PREDIA");lcd_gotoxy(9,1);lcd_puts
f("SESAAT");}
else if (val>=51
&& PINB.0==0)
{lcd_gotoxy(10,0);lcd_putsf("DIABET");lcd_gotoxy(9,1);lcd_puts
f("SESAAT");}
//60=264
else if (val<=43
&& PINB.0==1)
{lcd_gotoxy(10,0);lcd_putsf("NORMAL");lcd_gotoxy(9,1);lcd_puts
f("PUASA");}
//60=264
else if (val>=44 &&val<=46
&& PINB.0==1)
{lcd_gotoxy(10,0);lcd_putsf("PREDIA");lcd_gotoxy(9,1);lcd_puts
f("PUASA");}
else if (val>=46
&& PINB.0==1)
{lcd_gotoxy(10,0);lcd_putsf("DIABET");lcd_gotoxy(9,1);lcd_puts
f("PUASA");}
//60=264
if
if
(PINB.0==1){lcd_gotoxy(9,1);lcd_putsf("PUASA");}
(PINB.0==0){lcd_gotoxy(9,1);lcd_putsf("SESAAT");}
}
}
unsigned char fuzzifikasi_normal_puasa()
{
gula_normal=0;
if
(val<=43
{gula_normal=1;}
else if (val>=44 &&val<=45
{gula_normal=((45-adc)/2);}
else if (val>=46
{gula_normal=0;}
&& PINB.0==1)
&& PINB.0==1)
&& PINB.0==1)
returngula_normal;
}
unsigned char fuzzifikasi_predia_puasa()
{
gula_predia=0;
if
(val<=43
{gula_predia=0;}
else if (val>44 &&val<=45
{gula_predia=((adc-45)/2);}
else if (val>45 &&val<46
{gula_predia=((51-adc)/2);}
else if (val>=46
{gula_predia=0;}
&& PINB.0==1)
&& PINB.0==1)
&& PINB.0==1)
&& PINB.0==1)
returngula_predia;
}
unsigned char fuzzifikasi_diabet_puasa()
{
gula_diabet=0;
if
(val<=43
{gula_normal=0;}
else if (val>=44 &&val<=45
{gula_normal=((adc-46)/4);}
else if (val>=46
{gula_diabet=1;}
&& PINB.0==1)
&& PINB.0==1)
&& PINB.0==1)
returngula_diabet;
}
unsigned char fuzzifikasi_normal_sesaat()
{
gula_normal=0;
if
(val<=45
{gula_normal=1;}
else if (val>=46 &&val<=50
{gula_normal=((50-adc)/4);}
else if (val>=51
{gula_normal=0;}
&& PINB.0==0)
&& PINB.0==0)
&& PINB.0==0)
returngula_normal;
}
unsigned char fuzzifikasi_predia_sesaat()
{
gula_predia=0;
if
(val<=45
{gula_predia=0;}
&& PINB.0==0)
else if (val>45 &&val<=48
{gula_predia=((adc-45)/2);}
else if (val>=48 &&val<51
{gula_predia=((51-adc)/2);}
else if (val>=48
{gula_predia=0;}
&& PINB.0==0)
&& PINB.0==0)
&& PINB.0==0)
returngula_predia;
}
unsigned char fuzzifikasi_diabet_sesaat()
{
gula_diabet=0;
if
(val<=45
{gula_normal=0;}
else if (val>=46 &&val<=50
{gula_normal=(adc-46/4);}
else if (val>=51
{gula_diabet=1;}
&& PINB.0==0)
&& PINB.0==0)
&& PINB.0==0)
returngula_diabet;
}
voidfuzzifikasi()
{
fuzzifikasi_normal_puasa();
fuzzifikasi_predia_puasa();
fuzzifikasi_diabet_puasa();
fuzzifikasi_normal_sesaat();
fuzzifikasi_predia_sesaat();
fuzzifikasi_diabet_sesaat();
}
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=0x01;
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=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;
// 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
// USART disabled
UCSRB=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 691.200 kHz
// ADC Voltage Reference: AREF pin
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x84;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|CCompiler|Libraries|Alphanumeric LCD
menu:
// RS - PORTC Bit 0
// RD - PORTC Bit 1
// EN - PORTC Bit 2
// D4 - PORTC Bit 4
// D5 - PORTC Bit 5
// D6 - PORTC Bit 6
// D7 - PORTC Bit 7
// Characters/line: 16
lcd_init(16);
while (1)
{
// Place your code here
//
//
a0 deteksi strip
a1 60 ke 13 ke 60 barukenilai
adc();
lcd_adc();
if
(i1>=100 && i1<115 && i2>=100 && i2<115)
{
while(1)
{
lcd_gotoxy(11,0);
lcd_putsf("DARAH");
adc();
lcd_adc();
if
(i1>=10 && i1<35 && i2>=10 && i2<35)
{
lcd_gotoxy(11,0);
lcd_putsf("WAIT.");
delay_ms(6000);
while(1)
{
adc();
for (i=0;i<=5;i++)
{
adc();
val=i0;
delay_ms(500);
}
calculate();
}
}
}
}
else {
lcd_gotoxy(11,0);
lcd_putsf("STRIP");
}
}
}
Features
• High-performance, Low-power Atmel®AVR® 8-bit Microcontroller
• Advanced RISC Architecture
– 131 Powerful Instructions – Most Single-clock Cycle Execution
– 32 × 8 General Purpose Working Registers
– Fully Static Operation
– Up to 16 MIPS Throughput at 16MHz
– On-chip 2-cycle Multiplier
• High Endurance Non-volatile Memory segments
– 32Kbytes of In-System Self-programmable Flash program memory
– 1024Bytes EEPROM
– 2Kbytes Internal SRAM
– Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
– Data retention: 20 years at 85°C/100 years at 25°C
(1)
– Optional Boot Code Section with Independent Lock Bits InSystem Programming by On-chip Boot Program
True Read-While-Write Operation
– Programming Lock for Software Security
• JTAG (IEEE std. 1149.1 Compliant) Interface
– Boundary-scan Capabilities According to the JTAG Standard
– Extensive On-chip Debug Support
– Programming of Flash, EEPROM, Fuses, and Lock Bits through the JTAG Interface
• Peripheral Features
– Two 8-bit Timer/Counters with Separate Prescalers and Compare Modes
– One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture Mode
– Real Time Counter with Separate Oscillator
– Four PWM Channels
– 8-channel, 10-bit ADC
8 Single-ended Channels
7 Differential Channels in TQFP Package Only
2 Differential Channels with Programmable Gain at 1x, 10x, or 200x
– Byte-oriented Two-wire Serial Interface
– Programmable Serial USART
– Master/Slave SPI Serial Interface
– Programmable Watchdog Timer with Separate On-chip Oscillator
– On-chip Analog Comparator
• Special Microcontroller Features
– Power-on Reset and Programmable Brown-out Detection
– Internal Calibrated RC Oscillator
– External and Internal Interrupt Sources
– Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, Standby and
Extended Standby
• I/O and Packages
– 32 Programmable I/O Lines
– 40-pin PDIP, 44-lead TQFP, and 44-pad QFN/MLF
• Operating Voltages
– 2.7V - 5.5V for ATmega32L
– 4.5V - 5.5V for ATmega32
• Speed Grades
– 0 - 8MHz for ATmega32L
– 0 - 16MHz for ATmega32
• Power Consumption at 1MHz, 3V, 25°C
– Active: 1.1mA
– Idle Mode: 0.35mA
– Power-down Mode: < 1µA
The Atmel®AVR®AVR core combines a rich instruction set with 32
general purpose working registers. All the 32 registers are directly connected to the Arithmetic
Logic Unit (ALU), allowing two
independent registers to be accessed in one single
instruction executed in one clock cycle. The
resulting architecture is more code efficient while achieving
throughputs up to ten times faster
than conventional CISC microcontrollers.
The ATmega32 provides the following features: 32Kbytes of
In-System Programmable Flash
Program memory with Read-While-Write capabilities,
1024bytes EEPROM, 2Kbyte SRAM, 32
general purpose I/O lines, 32 general purpose working registers, a
JTAG interface for Boundary-
scan, On-chip Debugging support and programming, three flexible Timer/Counters
with compare modes, Internal and External Interrupts, a serial
programmable USART, a byte oriented
Two-wire Serial Interface, an 8-channel, 10-bit ADC with
optional differential input stage with
programmable gain (TQFP package only), a programmable Watchdog
Timer with Internal Oscil-
lator, an SPI serial port, and six software selectable power
saving modes. The Idle mode stops
the CPU while allowing the USART, Two-wire interface, A/D
Converter, SRAM, Timer/Counters,
SPI port, and interrupt system to continue functioning. The Powerdown mode saves the register
contents but freezes the Oscillator, disabling all other chip functions
until the next External Inter-
rupt or Hardware Reset. In Power-save mode, the
Asynchronous Timer continues to run,
allowing the user to maintain a timer base while the rest of
the device is sleeping. The ADC
Noise Reduction mode stops the CPU and all I/O modules
except Asynchronous Timer and
ADC, to minimize switching noise during ADC conversions.
In Standby mode, the crystal/resonator Oscillator is running while the rest of the device is
sleeping. This allows very fast start-up
combined with low-power consumption. In Extended
Standby mode, both the main Oscillator
and the Asynchronous Timer continue to run.
The device is manufactured using Atmel’s high density nonvolatile
memory technology. The Onchip ISP Flash allows the program memory to be reprogrammed insystem through an SPI serial
interface, by a conventional nonvolatile memory
programmer, or by an On-chip Boot program
running on the AVR core. The boot program can use any
interface to download the application
program in the Application Flash memory. Software in the Boot Flash
section will continue to run
while the Application Flash section is updated, providing true
Read-While-Write operation. By
combining an 8-bit RISC CPU with In-System SelfProgrammable Flash on a monolithic chip,
the Atmel ATmega32 is a powerful microcontroller that
provides a highly-flexible and cost-effective solution to many embedded control applications.
The Atmel AVR ATmega32 is supported with a full suite of
program and system development
tools including: C compilers, macro assemblers, program
debugger/simulators, in-circuit emulators, and evaluation kits.
Pin Descriptions
VCC
Digital supply voltage.
GND
Ground.
Port A (PA7..PA0)
Port A serves as the analog inputs to the A/D Converter.
Port A also serves as an 8-bit bi-directional I/O port, if the
A/D Converter is not used. Port pins
can provide internal pull-up resistors (selected for each bit). The Port
A output buffers have sym-
metrical drive characteristics with both high sink and source
capability. When pins PA0 to PA7
are used as inputs and are externally pulled low, they will
source current if the internal pull-up
resistors are activated. The Port A pins are tri-stated when a
reset condition becomes active,
even if the clock is not running.
PC1602A-L (16x2) Character LCD Display
Absolute Maximum Ratings at TA = 25 °C
Features
*16 Character, 2 Line
*View Angle 12H or 6H
*TN or STN Fluid
* Extended Temperature Range
available
*Several Character Types
available
*LED or EL Backlight available
Item
Symbol
Min
Max
Power Supply (Logic)
Vdd
-0.3
7.0
Power Supply (LCD)
Vo
Vdd – 0.3
Vdd 12.0
Input Voltage
Vi
- 0.3
Vdd
Operating Temperature (Standard)
Topr
0
50
Storage Temperature (Standard)
Tstg
- 20
70
Extended Operating Temperature
Topr
- 20
70
Extended Storage Temperature
Tstg
- 30
80
Electrical Characteristics at TA = 25 °C, Vdd=5V+0.25V
Item
Symbol
Min
Typ
Max
Vdd-Vss
4.7
5.0
5.3
Idd
—
2.0
3.0
Vdd -Vo
4.2
4.5
4.8
Input Voltage “H”
Vih
2.2
—
Vdd
Input Voltage “L”
Vil
—
—
0.6
Output Voltage “H”
Voh
2.4
—
—
Output Voltage “L”
Vol
—
—
0.4
Power Supply (Logic)
Supply Current
LCD Driving Voltage
U
m
Interface Pin Connection
No
Symbol
Function
No
Symbol
Function
1
Vss
Power Supply (GND)
9
DB2
Data Bus Line 2
2
Vdd
Power Supply (+5V)
10
DB3
Data Bus Line 3
3
Vo
Contrast Adjust
11
DB4
Data Bus Line 4
4
RS
Instruction/Register Select
12
DB5
Data Bus Line 5
5
R/W
Read/Write
13
DB6
Data Bus Line 6
6
E
Enable Signal
14
DB7
Data Bus Line 7
7
DB0
Data Bus Line 0
15
A
Power Supply for LED Backlight
8
DB1
Data Bus Line 1
16
K
Power Supply for LED Backlight
LED Backlight Specifications
Forward Voltage
Forward Current
Power Dissipation
Peak Wavelength
4.2V (Typ)
195mA (Max)
900mW (Max)
570nm (Typ)
Mechanical Specifications
Item
Overall Size
Viewing Area
Character Size
Character Pitch
Dot Siz
Specifications
80.0W x 36.0H x 8.8T (BL12.7T)
65.0W x 16.0H
2.96W x 5.56H
3.55W x 5.94H
0.56W x 0
All dimensions are in mm. Tolerance is ± 0.3 Unless otherwise specified
© Copyright 2025 Paperzz