An AVR C program is described that performs the following tasks:
1. Sends values from 00-FF to Port B.
2. Sends hex values for ASCII characters 0-5 and A-D to Port D.
3. Toggles all bits of Port C 200 times.
A second AVR C program is described that sends values from -4 to +4 to Port B.
An AVR C program is described that performs the following tasks:
1. Sends values from 00-FF to Port B.
2. Sends hex values for ASCII characters 0-5 and A-D to Port D.
3. Toggles all bits of Port C 200 times.
A second AVR C program is described that sends values from -4 to +4 to Port B.
An AVR C program is described that performs the following tasks:
1. Sends values from 00-FF to Port B.
2. Sends hex values for ASCII characters 0-5 and A-D to Port D.
3. Toggles all bits of Port C 200 times.
A second AVR C program is described that sends values from -4 to +4 to Port B.
An AVR C program is described that performs the following tasks:
1. Sends values from 00-FF to Port B.
2. Sends hex values for ASCII characters 0-5 and A-D to Port D.
3. Toggles all bits of Port C 200 times.
A second AVR C program is described that sends values from -4 to +4 to Port B.
Download as PPTX, PDF, TXT or read online from Scribd
Download as pptx, pdf, or txt
You are on page 1of 13
Simple lab Demo
1. Write an AVR C program sends values 00-FF to Port
B. 2. Write an AVR C program sends hex values for ASCII characters of 0,1,2,3,4,5,A,B,C,D to Port D. 3. Write AVR C program toggles all the bits of Port C 200 times. 4. Write AVR C program to send values of -4 to +4 to Port B. I/O PROGRAMMING IN C Logic Operation In C • One of the most important and powerful features of the C language is its ability to perform bit manipulation. • This section describes the action of bitwise logic operators and provides some examples of how they are used. • The bitwise operators used in C are • AND (&), OR ( | ), EX-OR ( ^ ), inverter (~), Shift right (>>) and Shift left (<<). • These are widely used in software engineering for embedded systems and control; • Consequently, understanding and mastery of them are critical in microprocessor and microcontroller-based system design and interfacing. The operations are shown in table below. I/O PROGRAMMING IN C LAB DEMO 1. Write an AVR C program to toggle only bit 4 of Port B continuously without disturbing the rest of the pins of Port B. 2. Write an AVR C program to monitor bit 5 of port C. If it is HIGH, send 55H to Port B; otherwise, send AAH to Port D. 3. A door sensor is connected to bit 1 of Port B, and an LED is connected to bit 7 of Port C. Write an AVR C program to monitor the door sensor and, when it opens, turn on the LED. Lab Exercise 1. The data pins of an LCD are connected to Port D. The information is latched into the LCD, whenever its Enable pin goes from LOW to HIGH to. The enable pin is connected to pin 5 of Port B (6th pin). Write a C program to send The “Am software Engineering students" to this LCD.
2. Write an AVR C program to monitor bit
7 of Port B. If it is 1 make bit 4 of Port B input; otherwise, change pin 4 of Port B to output Bit-wise shift operators Data Conversion • Many systems have what is called a real-time clock (RTC). The RTC provides the time of day (hour, minute, second) and the date (year, month, day) continuously, regardless of whether the power is on or off • However, this data is provided in packed BCD. • For this data to be displayed on a device such as an LCD, or to be printed by the printer, it must be in ASCII format. • To convert packed BCD to ASCII, it must first be converted to unpacked BCD. Then the unpacked BCD is tagged with (30H). • The following demonstrates converting from packed BCD to ASCII Data Conversion • To convert packed BCD to ASCII, it must first be converted to unpacked BCD. • Then the unpacked BCD is tagged with 0011 0000 (30H). • The following demonstrates converting from packed BCD to ASCII.
ASCII to packed BCD conversion
• To convert ASCII to packed BCD, it is first converted to unpacked BCD (to get rid of the 3), and then combined to make packed BCD. • For example, for 4 and 7 the keyboard gives 34 and 37, respectively. The goal is to produce 47H or “0100 0111″, which is packed BCD Lab demo 1. Write an AVR C program to convert packed BCD 0x29 to ASCII and display the bytes on PORTB and PORTC. 2. Write an AVR C program to convert ASCII digits of '4‘ and '7' to packed BCD and display them on PORTB. INTERRUPT PROGRAMMING 3. Assume that the INT0 pin is connected to a switch that is normally high. Write a program that toggles PORTA.3, whenever INT0 pin goes low. Use the external interrupt in level-triggered mode. simple steps • Setting up PORTA.3 as an output • Configuring INT0 pin as input with pull-up resistor: • Configuring external interrupt INT0 in level- triggered mode: • Enabling external interrupt INT0 • Enabling global interrupts • ISR for external interrupt INT0 Steps to program Timer0 in Normal mode 1. Load the TCNT0 register with the initial count value. 2. Load the value into the TCCR0 register, indicating which mode (8-bit or 16-bit) is to be used and the prescaler option. When you select the clock source, the timer/counter starts to count, and each tick causes the content of the timer/counter to increment by 1. 3. Keep monitoring the timer overflow flag (TOVO) to see if it is raised. Get out of the loop when TOVO becomes high. 4. Stop the timer by disconnecting the clock source, using the following instructions: 5. Clear the TOVO flag for the next round. 6. Go back to Step 1 to load TCNT0 again. Calculating Delay Length Using Timers
InOutPelan Induk Perindustrian (PIP) 1986 Pengenalan Sejak mencapai kemerdekaan, kerajaan Malaysia telah menggiatkan usaha kearah mewujudkan Malaysia sebagai sebuah Negara perindustrian. Usaha ini merupakan satu langkah baharu kerajaan untuk mempelbagaikan sektor ekonomi Negara supaya tidak hanya bergantung kepada getah dan bijih timah sahaja. • Usaha kerajaan bukan sahaja untuk memajukan Negara dengan cara mempelbagaikan kegiatan perindustrian, tetapi juga untuk menyediakan peluang pekerjaan yang lebih banyak kepada rakyat. Selain menyediakan peluang pekerjaan, sektor ini juga akan dapat menjadi pengeksport utama Negara dan menyediakan latihan teknikal serta kemahiran kepada rakyat tempatan. • Memandangkan dasar kerajaan untuk menjadikan sektor perindustriam sebagai industi utama Negara dalam jangka masa panjang, pihak kerajaan telah menubuhkan satu jawatankuasa kajian Dasar Perindustrian Negara dan Pelan Induk Perindustrian (PIP) pada 3 Febuari 1986 untuk menyemak