#include <avr/io.h>
#include <util/delay_basic.h>
void Onems(uint8_t delay)
{
//One ms delay
uint8_t i,j;
for(i=0;i<32;i++)
{
for(j=0;j<10;j++)
{
_delay_loop_1(32);
}
}
}
int main()
{
uint16_t count1,count2;
// uint8_t tim=250;
//Set the PORTD7 as output
DDRB=0B00000000; // all bit and b4 as INPUT
PORTB|=(1<<PB4);
DDRD=0b10000000; // D7 as O/P
PORTD |=0B10000000;
while(1)
{
count1=0;
count2=0;
while (PINB4==1)
{
Onems(100);
count1=count1+10;
Onems(10);
count1 = count1 + 1;
PORTD |=0B10000000;
}
while (PINB4==0)
{
Onems(100);
count1=count2+10;
Onems(10);
count2 = count2 + 1;
PORTD &=0B01111111;
}
}
I could not understand it but I know the value of his posts, it must be containing what I am looking for and will carefully examine details to find answer to my query.
Code C - [expand] 1 2 3 4 5 6 // add this defines #define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT)) #define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT)) #define FLIPBIT(ADDRESS,BIT) (ADDRESS ^= (1<<BIT)) #define CHECKBIT(ADDRESS,BIT) (ADDRESS & (1<<BIT)) #define WRITEBIT(RADDRESS,RBIT,WADDRESS,WBIT) (CHECKBIT(RADDRESS,RBIT) ? SETBIT(WADDRESS,WBIT) : CLEARBIT(WADDRESS,WBIT))
Instead of PORTB|=(1<<PB4); you can use SETBIT(PORTB,PB4);
Instead of PORTD |=0B10000000; you can use SETBIT(PORTD,7);
Instead of PORTD &=0B01111111; you can use CLEARBIT(PORTD,7);
Instead of while (PINB4==1) ([COLOR="#FF0000"]which is not valid by the way[/COLOR]) you can use while (CHECKBIT(PINB,4));
#define PINB7 7
#define PINB6 6
#define PINB5 5
#define PINB4 4
#define PINB3 3
#define PINB2 2
#define PINB1 1
#define PINB0 0
while (PINB4==1)
{
Onems(100);
count1=count1+10;
Onems(10);
count1 = count1 + 1;
PORTD |=0B10000000;
}
while (PINB4==0)
{
Onems(100);
count[COLOR="#FF0000"]1[/COLOR]=count2+10;
Onems(10);
count2 = count2 + 1;
PORTD &=0B01111111;
}
while(1)
{
count1=0;
count2=0;
while (CHECKBIT(PINB,4))
{
Onems(1);
count1++;
PORTD = 0b10000000;
}
while (!CHECKBIT(PINB,4))
{
Onems(1);
count2++;
PORTD = 0b0000000;
}
}
#include <util/delay_basic.h>
void Onems(uint8_t delay)
{
//One ms delay
uint8_t i,j;
for(i=0;i<32;i++)
{
for(j=0;j<10;j++)
{
_delay_loop_1(32);
}
}
}
#include <util/delay.h>
_delay_us();
_delay_ms();
Now things seem to be under control and I will make the changes and hope it will work fine.../PulseRate2.c:40: warning: implicit declaration of function 'SETBIT'
The command SETBIT is giving a warning
#define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT))
#define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT))
#define FLIPBIT(ADDRESS,BIT) (ADDRESS ^= (1<<BIT))
#define CHECKBIT(ADDRESS,BIT) (ADDRESS & (1<<BIT))
#define WRITEBIT(RADDRESS,RBIT,WADDRESS,WBIT) (CHECKBIT(RADDRESS,RBIT) ? SETBIT(WADDRESS,WBIT) : CLEARBIT(WADDRESS,WBIT))
True, very tru!
This delay fuction will simplify many things, The delay used by me from
#include <util/delay_basic.h>
had different functionality from claim, it is claimed that at 1 MHz it is expected to give 768 micro second but with 16 MHz too it gives the same 768 (I did not try 1 MHz).
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?