project ini dibuat berbasis uC AVR ATMega8535 dengan tampilan LCD 16×2 dan menggunakan bahasa C CodevisionAVR sebagai kompilernya. PORTA.0 di set sebagai pin SDA dan PORTA.1 di set sebagai pin SCL.
berikut ini adalah potongan sourcecode dari project sensor suhu ds1621 :
untuk full source code harus melakukan donasi ya bro,,email aja ke >>> songolikur@gmail.com
001 | /***************************************************** |
002 | This program was produced by the |
003 | CodeWizardAVR V1.25.3 Professional |
004 | Automatic Program Generator |
005 | © Copyright 1998-2007 Pavel Haiduc, HP InfoTech s.r.l. |
007 |
008 | Project : |
009 | Version : |
010 | Date : 5/8/2009 |
011 | Author : GreenBlack |
012 | Company : LakoV |
013 | Comments: |
014 |
015 | Chip type : ATmega8535 |
016 | Program type : Application |
017 | Clock frequency : 11.059200 MHz |
018 | Memory model : Small |
019 | External SRAM size : 0 |
020 | Data Stack size : 128 |
021 | *****************************************************/ |
022 |
023 | #include <mega8535.h> |
024 | #include <delay.h> |
025 | #include <stdio.h> |
026 | #include <math.h> |
027 |
028 | #asm |
029 | .equ __lcd_port=0x15 ;PORTC |
030 | #endasm |
031 |
032 | // Declare your global variables here |
033 | unsigned char lcd_buffer[33]; |
034 |
035 | void main( void ) |
036 | { |
037 | // Declare your local variables here |
038 | int suhu,t0; |
039 |
040 | // Input/Output Ports initialization |
041 | // Port A initialization |
042 | // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In |
043 | // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T |
044 | PORTA=0x00; |
045 | DDRA=0x00; |
046 |
047 | // Port B initialization |
048 | // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In |
049 | // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T |
050 | PORTB=0x00; |
051 | DDRB=0x00; |
052 |
053 | // Port C initialization |
054 | // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In |
055 | // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T |
056 | PORTC=0x00; |
057 | DDRC=0x00; |
058 |
059 | // Port D initialization |
060 | // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In |
061 | // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T |
062 | PORTD=0x00; |
063 | DDRD=0x00; |
064 |
065 | // Timer/Counter 0 initialization |
066 | // Clock source: System Clock |
067 | // Clock value: Timer 0 Stopped |
068 | // Mode: Normal top=FFh |
069 | // OC0 output: Disconnected |
070 | TCCR0=0x00; |
071 | TCNT0=0x00; |
072 | OCR0=0x00; |
073 |
074 | // Timer/Counter 1 initialization |
075 | // Clock source: System Clock |
076 | // Clock value: Timer 1 Stopped |
077 | // Mode: Normal top=FFFFh |
078 | // OC1A output: Discon. |
079 | // OC1B output: Discon. |
080 | // Noise Canceler: Off |
081 | // Input Capture on Falling Edge |
082 | // Timer 1 Overflow Interrupt: Off |
083 | // Input Capture Interrupt: Off |
084 | // Compare A Match Interrupt: Off |
085 | // Compare B Match Interrupt: Off |
086 | TCCR1A=0x00; |
087 | TCCR1B=0x00; |
088 | TCNT1H=0x00; |
089 | TCNT1L=0x00; |
090 | ICR1H=0x00; |
091 | ICR1L=0x00; |
092 | OCR1AH=0x00; |
093 | OCR1AL=0x00; |
094 | OCR1BH=0x00; |
095 | OCR1BL=0x00; |
096 |
097 | // Timer/Counter 2 initialization |
098 | // Clock source: System Clock |
099 | // Clock value: Timer 2 Stopped |
100 | // Mode: Normal top=FFh |
101 | // OC2 output: Disconnected |
102 | ASSR=0x00; |
103 | TCCR2=0x00; |
104 | TCNT2=0x00; |
105 | OCR2=0x00; |
106 |
107 | // External Interrupt(s) initialization |
108 | // INT0: Off |
109 | // INT1: Off |
110 | // INT2: Off |
111 | MCUCR=0x00; |
112 | MCUCSR=0x00; |
113 |
114 | // Timer(s)/Counter(s) Interrupt(s) initialization |
115 | TIMSK=0x00; |
116 |
117 | // Analog Comparator initialization |
118 | // Analog Comparator: Off |
119 | // Analog Comparator Input Capture by Timer/Counter 1: Off |
120 | ACSR=0x80; |
121 | SFIOR=0x00; |
122 |
123 | lcd_init(16); |
124 |
125 | lcd_gotoxy(0,0); |
126 | lcd_putsf( "== TERMOMETER ==" ); |
127 |
128 | while (1) |
129 | { |
130 | // Place your code here |
131 | lcd_gotoxy(0,1); |
132 | t0=ds1621_temperature_10; |
133 | suhu=t0/10; |
134 | sprintf ( " Temp: %-d.%-d%cC " ,suhu, abs (t0%10),0xDF); //0xDF adalah karakter derajat |
135 | lcd_puts(lcd_buffer); |
136 | delay_ms(100); |
137 | }; |
138 | } |