Programing code that does the following requirements, hopefully I can find someo
ID: 2084446 • Letter: P
Question
Programing code that does the following requirements, hopefully I can find someone who will help me this I/O hardware using C++ problem. Thanks
In this lab you will learn how to interface with the I/O hardware using C++. You will gain experience reading the hardware data-sheet to gain the information necessary to manage the l/o port registers Upon completion of this lab, students will be able to: st all the ports of the AVR Describe the dual role of the AVR pins Write code to use the ports for input and output Code lo bit-manipulation programs for the AVR Explain bit-addressability of AVR ports Become familiar with C++ bitwise operators To achieve the learning objectives, students are expected to complete the following attend lecture attend lab Hardware Interfacing overview An important source of information when tackling a hardware interfacing project is the data sheet document. Before any hardware component (eg, micro-controller, communication board, etc.) can be controlled via software, there must be a document specifying the ways in which software can control the hardware. For the ATMega 328p, all of the necessary information required for interfacing is contained in its data sheet The data sheet for the ATMega 328p contains complete information about the IC, including a general block diagram, pin configurations. l/o multiplexing, CPU core, memories, buses, etc. In this module, we are interested in controlling the l/o ports, which is done via the general purpose I/O registers. As previously discussed, the ATMega 328p includes three ports: Port which manages the analog pins A0 AS: Port D, which manages digital pins 0-7. and Port B which manages pins 8-13. lfwe take a look at the data sheet, we see that each port is controlled via three registers, namely: PORT e DDR. e PIN At this point, it is important to go over a bit of convention. Since each port is associated with a version of the three interfacing registers mentioned above, we need a way to specify the correct name of the register we're interested in working with. For example, if we are interested in working with the PIN register associated with Port B, we will refer to it as PINB. Similarly, if we are interested in working with the PIN register of Port D, we would refer to it as PIND, and the same applies for Port C. Now, each register is associated with a set of bits, so to fully qualify a specific bit location, we would append the bit number to the desired register name. That is, if we are interested in looking up the value of bit 2 of the PINB register, we would referto it as PINB2. As example, consider the information below, extracted from the datasheet.Explanation / Answer
C++ CODE FOR BLINKING LEDS IN AVR (arduino):
void setup(){
DDRB=0X03;
DDRD=0X03;
}
void loop(){
PORTD^=0x03;
delay(500);
PORTB^=0x03;
delay(500);
}
======================
User defined I/O function prototypes:
void digitalWriteGeneric(unsigned char pin_number,unsigned char pin_setting){
if(pin_number<8){
if(pin_setting==1)
PORTD|= 1<<pin_number;
else
PORTD&= ~(1<<pin_number);
}else{
pin_number=pin_number-8;
if(pin_setting==1)
PORTB|= 1<<pin_number;
else
PORTB&= ~(1<<pin_number);
}
}
int digitalReadGeneric(unsigned char pin_number){
if(pin_number<8){
return (boolean) PIND&(1<<pin_number) ;
}else{
return (boolean) PINB&(1<<pin_number) ;
}
}
void pinModeGeneric(unsigned char pin_number,unsigned char data_direction){
if(pin_number<8){
char mask=1<<pin_number;
if(data_direction==1)
DDRD|=mask;
else
DDRD&= ~mask;
}else{
pin_number=pin_number-8;
char mask=1<<pin_number;
if(data_direction==1)
DDRB|=mask;
else
DDRB&= ~mask;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.