Laboratory Report (For Online Lab Class Only) : ECTE333: Microcontroller Architecture and Application Spring 2020 Session
Laboratory Report (For Online Lab Class Only) : ECTE333: Microcontroller Architecture and Application Spring 2020 Session
Laboratory Report (For Online Lab Class Only) : ECTE333: Microcontroller Architecture and Application Spring 2020 Session
void serial_init(void)
{
UCSRC = 0b10000110; // Asynchronous mode, no parity, 1 stop bit, 8 data bits
UCSRA = 0b00000000; // Normal speed, disable multi proc
int main(void)
{
unsigned char key; //Key pressed
unsigned char prev_key = 0;
DDRB = 0b11110000; //Keypad linked with PORTB
DDRA = 0b11111111; //PORTA set as all 1’s meaning output for LEDs
serial_init();
while(1)
{
key = read_keypad();
if(key!=0 && key!= prev_key){ //same key isn’t being pressed,avoid repitition
LED_ON(key);
serial_send(key);
Page 1
}
}
}
DDRB = 0b11110000;
//Scan the keypad to find which key is being pressed
key = 0;
for (col = 1;col<=3;col++){
//Send binary 0 to corresponding pin for the column
PORTB = ~(1<<(keypad_col_bit[col-1]));
Page 2
PORTA = 0b01111111;
break;
case '8':
PORTA = 0b00000000;
break;
case '9':
PORTA = 0b00000000;
break;
case '*': // “*” key pressed
PORTA = 0b00000000;
break;
case '#': //
PORTA = 0b00000000;
break;
default:
NOP;
}
}
c) Comments on the expected results and any anticipated problems with the C program. .
The expected results are that once you press the key on the keypad, the same key should be displayed on the seven
segment displays LED’s. This can be verified using hyperlink if we don’t have the display. The baud rate is 1200,
with 1 stop bit and no parity bit. The number pressed should be displayed once only in the hyper terminal not
multiple times.
Problems:
The baud rate has to be consistent, if they don’t line up the code will fail and garbage might appear.
When verifying the program with the hyperterminal software, pushing down the button will give repeated outputs.
To rectify this an if statement is needed and a delay needs to be placed in between reads.
Use the assembly instruction to with nop, using only nop might not work correctly in all situations.
Make sure Rx and Tx are connected to the correct ports, otherwise the received data and send data channels will
be interchanged causing incorrect results
Page 3
}
}
int main(void)
{
init_USART(); //Initialise USART
//Timer Initialisation
TCCR1A = 0b00000000; // selected normal mode
TCCR1B = 0b11000001; // no pre-scalar, rising edge
TIMSK = 0b00100100; // ENABLE the timer_1 capture_interrupt
while (1)
{
printf("/n/Frequency = %ld Hz, period = %ld ms", freq, period) //display period and frequency
PORTB = ~(freq); //compensate for active low LED
return 0;
}
}
c) Comments on the expected results and any anticipated problems with the C program. .
The connected oscilloscope can visualize a square wave, the measured frequency of the waves is represented using
the LED’s (top 8 bits). The hyperterminal is used to display the signal period and frequency.
Problems:
Page 4
We had to use uint_32 because we were dealing with large numbers that might not necessarily be storable in a
16-bit space.
The timer can only store the period upto 65536 hence we needed to use an overflow as a trigger to get the results
The global interrupt have to be enabled using the sei() otherwise the program wont work.
void serial_init(void){
// Asynchronous mode, no parity, 1 stop bit, 8 data bits
UCSRC = 0b10000110;
int serial_receive(void){
// Wait until RXC flag = 1
while ((UCSRA & (1 << RXC)) == 0x00){;}
// Read the received char from UDR
return (UDR);
}
serial_init(); //Initialize
stdout = fdevopen(serial_send,NULL); //Initialize standard I/O handlers
stdin = fdevopen(NULL,serial_receive);
void serial_init(void){
//Control & Status Registers
//UCSRA- No setting
Page 6
UCSRA = 0b00000000;
int main(void)
{
DDRB=0xFF; //configuring PORTB as output (all 1’s)
unsigned int analog,digital; //int variable designed to hold analog and digital results
c) Comments on the expected results and any anticipated problems with the C program. .
The program is expected to get an analog input from an LDR or any source and convert it into an digital value, the
hyperterminal must display both the digital and analogue values. The analogue voltage is connected to PORT A
pin6 and the program should continuously output the info in the hyper terminal. The program configures the
serial port for a baud rate of 2400 bps, 8-data bit, 1-stop bit, no parity bit, flow control OFF.
Problems foreseen:
We have been using 1200 baud rate for all the previous lab, hence we have to edit the initializing serial part to set
the baud rate to 2400 else the output will not be accurate.
We have to make sure to use the correct formula according to the alignment, using the wrong formulae will lead
to an incorrect output.
There are many ways to convert Analog to Digital, and the method we used is not versatile enough to handle all
possible analog to digital conversions.
Page 8