Hello Dear friends , i am generating six signals shifted from each other .I have done the shifting work and it is working fine .
I am using delay() function for giving those delays or shifts .But i need to vary that delay() generated .I mean i need to generate a variable delay code .I have written a code ,showing the value of OCR0 which changes when i interrupt externally .The program works fine in AVR studio but it is not working in proteus .i am attaching the files required
kindly download the code and check and help me regarding this problem .. Click on Code.txt for code and on image for proteus design .
View attachment code.txt
Code C - [expand ] 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include<avr/io.h>
#include<avr/interrupt.h>
#include<util/delay.h>
void delay( ) ;
void lcdcommand( unsigned char cmnd) // function for sending command to lcd
{
PORTC= cmnd;
PORTA &= ~( 1 << 0 ) ; //Rs=0 for command
PORTA &= ~( 1 << 1 ) ; //Rw=0 for write
PORTA |= ( 1 << 2 ) ; //En=1
_delay_us( 1 ) ;
PORTA &= ~( 1 << 2 ) ; //En=0 for H.L pulse
_delay_us( 100 ) ;
}
void lcddata( unsigned char data) // function for sending data to lcd
{
PORTC= data;
PORTA |= ( 1 << 0 ) ; //Rs=1 for data
PORTA &= ~( 1 << 1 ) ; //Rw=0 for write
PORTA |= ( 1 << 2 ) ; //En=1
_delay_us( 1 ) ;
PORTA &= ~( 1 << 2 ) ; //En=0 for H.L pulse
_delay_us( 100 ) ;
}
void lcd_init( ) // function for initialization of lcd
{
DDRC= 0xFF ;
DDRA= 0xFF ;
PORTD &= ~( 1 << 2 ) ; //En=0
_delay_us( 2000 ) ;
lcdcommand( 0x38 ) ;
lcdcommand( 0x0E ) ;
lcdcommand( 0x01 ) ;
_delay_us( 2000 ) ;
lcdcommand( 0x06 ) ;
}
void lcd_gotoxy( unsigned char x, unsigned y) // function for locating cursor
{
unsigned char firstcharAdr[ ] = { 0x80 , 0xC0 , 0x94 , 0xD4 } ;
lcdcommand( firstcharAdr[ y- 1 ] + x- 1 ) ;
_delay_us( 100 ) ;
}
void lcd_print( char * str) // function for displaying the data
{
unsigned char i= 0 ;
while ( str[ i] != 0 )
{
lcddata( str[ i] ) ;
i++;
}
}
int main ( void )
{
lcd_init( ) ;
DDRB= 0xFF ;
DDRD&= 0xF3 ;
lcd_init( ) ;
int i= 0 ;
GICR |= ( 1 << INT0) | ( 1 << INT1) ;
MCUCR = 0x05 ;
sei( ) ;
lcd_print( "%dutycycle " ) ;
while ( 1 )
{
for ( i= 0 ; i<= 5 ; i++ )
{
if ( i== 0 )
{
PORTB|= 0b00110001 ;
delay( ) ;
PORTB&= 0b00100001 ;
}
else if ( i== 1 )
{
PORTB|= 0b00100011 ;
delay( ) ;
PORTB&= 0b00000011 ;
}
else if ( i== 2 )
{
PORTB|= 0b00000111 ;
delay( ) ;
PORTB&= 0b00000110 ;
}
else if ( i== 3 )
{
PORTB|= 0b00001110 ;
delay( ) ;
PORTB&= 0b00001100 ;
}
else if ( i== 4 )
{
PORTB|= 0b00011100 ;
delay( ) ;
PORTB&= 0b00011000 ;
}
else if ( i== 5 )
{
PORTB|= 0b00111000 ;
delay( ) ;
PORTB&= 0b00110000 ; }
}
}
return 0 ;
}
void delay( )
{
TCNT0= 0 ;
OCR0= 102 ;
TCCR0= 0x0C ;
while ( ( TIFR & 0x2 ) == 0 ) ;
TCCR0= 0 ;
TIFR|= ( 1 << OCF0) ;
}
ISR ( INT0_vect) // Increasing
{
unsigned char i;
i= OCR0;
if ( i>= 255 )
{
i= 255 ; }
else
i= i+ 13 ;
OCR0= i;
unsigned char hund, ten , unit, k, h;
h= OCR0;
hund= h/ 100 ;
hund= hund | 0x30 ;
ten= h% 100 ;
k= ten/ 10 ;
ten= k | 0x30 ;
unit= k% 10 ;
unit = unit| 0x30 ;
lcddata( hund) ;
lcddata( ten) ;
lcddata( unit) ;
}
ISR ( INT1_vect) //decreasing
{
unsigned char j;
j= OCR0;
if ( j>= 255 )
{
j= 255 ; }
else
j= j- 13 ;
OCR0= j;
unsigned char hund, ten , unit, k, l;
l= OCR0;
hund= l/ 100 ;
hund= hund | 0x30 ;
ten= l% 100 ;
k= ten/ 10 ;
ten= k | 0x30 ;
unit= k% 10 ;
unit = unit| 0x30 ;
lcddata( hund) ;
lcddata( ten) ;
lcddata( unit) ;
}
Last edited by a moderator: May 1, 2014