Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Simple C codevision question ,, plz help

Status
Not open for further replies.

Terminator Electricity

Member level 5
Joined
Feb 2, 2006
Messages
91
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,973
codevision array

Hi

what does these lines mean ?

what does the following expression mean ?

if(Array & a) ,, while array is a variable hexadecimal value ,, and 'a' is a constant hexadecimal value

and what does this mean ?
a <<= 1;

Thanks ,,
 

lambtron

Full Member level 5
Joined
Nov 2, 2005
Messages
251
Helped
34
Reputation
68
Reaction score
8
Trophy points
1,298
Location
Portland, OR
Activity points
3,547
codevision printf

Terminator Electricity said:
if(Array & a)

If the boolean AND of Array and a is non-zero ...

Terminator Electricity said:
Shift left a by one bit and store result in a.
 

Terminator Electricity

Member level 5
Joined
Feb 2, 2006
Messages
91
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,973
codevision printf time

Thanks for ur help ,, everything is now clear ,,,,

by the way ,,, do u have an idea how to write an interrupt driven IR RC% code ? cuz i made one with only a timer and it worked perfectly ,, but i have no idea how to start writing the code using interrupt
 

lambtron

Full Member level 5
Joined
Nov 2, 2005
Messages
251
Helped
34
Reputation
68
Reaction score
8
Trophy points
1,298
Location
Portland, OR
Activity points
3,547
codevision shift left code

Terminator Electricity said:
do u have an idea how to write an interrupt driven IR RC% code ? cuz i made one with only a timer and it worked perfectly ,, but i have no idea how to start writing the code using interrupt
You need a hardware timer for timing the ir pulses, and you must generate interrupts in response to one or both ir pulse edges. The isr should record snapshots of the hardware timer, and then the timer snapshots can be correlated after the ir pulse burst is complete.
 

Terminator Electricity

Member level 5
Joined
Feb 2, 2006
Messages
91
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,973
codevision printf sample

what do u mean by isr ?

This is my code for IR RC5 reciever using an ATmega16

Code:
/*****************************************************



Chip type           : ATmega16L
Program type        : Application
Clock frequency     : 7.372800 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 256
*****************************************************/

 
void setup_AVR(); 
#define CHECKBIT(ADDRESS,BIT) (ADDRESS & (1<<BIT))
#include <mega16.h>  
#include <stdio.h> 
#include <io.h>
unsigned char temp=0;
unsigned char command[10]={0};
unsigned char system[10]={0};
unsigned char timerH=0;
unsigned char timerL=0; 
int bitcnt;                     //number of bits waiting to be recieved
unsigned char ref1;                     // 3/4 bit_time
unsigned char ref2;                     // 5/4 bit_time     
int i=6;   
int j=5;
int k; 

interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
timerL++;                              //increments every 255* 1/7.372800 seconds
temp++;                              
if(temp==255) {temp=0;timerH++;} //increments every 255*255* 1/7.372800  seconds
}

void main(void)
{
setup_AVR();



#asm("sei")

while (1)
      {  

initialize:	temp=0; 
		timerH=0;   
            
detect1:	timerL=0;  
              
detect2:	if(timerH>15)	//If no start bit detected within 132ms
                goto fault;
                                
		if(timerL>102)	//If line high for more than 3.5ms
		goto start1;	//then wait for the first start bit

		if(!CHECKBIT(PIND,2))	        //If line is :
		     goto detect1;	// PIND=0  low  - jump to detect1 and reset the timer
		else goto detect2;	// PIND=1  high - jump to detect2 and recheck for 3.5 ms of ideal high

start1:		while(CHECKBIT(PIND,2))//keep checking for the first start bit
                {
                if(timerH>15)	//If no start bit detected within 132ms 
                 goto fault;	//then exit    printf("5");
                }

		timerL=0;	//Measure halflength of start bit     
		
start2:		while(!CHECKBIT(PIND,2))//Measure halflength of start bit (low level length) 
                {
                if(timerL>26)	//If startbit longer than 1.1ms,
		goto fault ;	//   exit
                }
                //timerL = 1/2 bit time
		ref1 =3.0*timerL/2.0;        //ref1 = 3/4 bit time
		ref2 =5.0*ref1/3.0;        //ref2 = 5/4 bit time
                timerL=0; 
                
start3:		while(CHECKBIT(PIND,2))//check if second starting bit is recieved
                {
                if(timerL>ref1)	//If rising edge is too long
		goto fault;	//exit
                }
                
		bitcnt  =12;	//Receive 12 bits
                j=5;            //For command
                i=5;            //For system
sample:		timerL  =0 ;
                while(timerL<ref1); // wait untill first 1/4 of next bit	
                
                while(bitcnt>0)
                
		{ 
		//Now recieving first 7 bits including the toggle bit
		while(bitcnt>6)
		     { if (PIND.2==0){                             //The bit recieved is 0
		                        system[i]=0;               //store the bit in system
		                        i-- ;bitcnt--;             //prepare for the next bit
		                        while(!CHECKBIT(PIND,2))   //wait untill the next edge
		                          {
		                          if(timerL>ref2) goto fault;
		                          }
		                        goto sample;               //wait for the next bit
		                     }
                      
                       else          {                             //The bit recieved is 1
                                        system[i]=1;               //store the bit in system
                                        i-- ;bitcnt--;             //prepare for the next bit
                                        while(CHECKBIT(PIND,2))    //wait untill the next edge
                                          {
                                          if(timerL>ref2) goto fault;
                                          }
                                        goto sample;               //wait for the next bit
                                     }
                     }                  
                //Now recieving last 6 bits
                                                                                      
                if(PIND.2==0){                                     //The bit recieved is 0
                                command[j]=0;                      //store the bit in command
                                j-- ;bitcnt--;                     //prepare for the next bit
                                while(!CHECKBIT(PIND,2))           //wait untill the next edge
                                  {
                                  if(timerL>ref2) goto fault;
                                  }
                                goto sample;                       //wait for the next bit
                              }                                  
               
                else         {                                      //The bit recieved is 1
                                command[j]=1;                       //store the bit in command
                                j-- ;bitcnt--;                      //prepare for the next bit
                                while(CHECKBIT(PIND,2))             //wait untill the next edge
                                  {
                                  if(timerL>ref2) goto fault;
                                  }
                                goto sample;                        //wait for the next bit
                             }
               }       
                


   
printf("aa");
for(k=5;k>=0;k--)
printf("%d",command[k]);
printf("bb");
for(k=5;k>=0;k--)
printf("%d",system[k]);

fault:		goto initialize;

      };
}
void setup_AVR()
{
PORTD=0x00;
DDRD=0x00;
TCCR0=0x01;
TCNT0=0x00;
OCR0=0x00;
TIMSK=0x01;
ACSR=0x80;
SFIOR=0x00;
}
how do i change it to be interrupt driven ?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top