Sie sind auf Seite 1von 26

Practical 1

Toggle Port LED

Write a program in Assembly/C programming language to alternately ON/OFF LEDs connected to two different ports. Draw appropriate circuit diagram to demonstrate the above problem.

Code:
#include <90s8535.h> #include <delay.h> void main(void) { DDRA=0xff; PORTA=0xff; DDRB=0xff; PORTB=0x00; //Unmasking the interrupt #asm("sei"); while (1) { delay_ms(2000); PORTA=PORTA^0xff; PORTB=PORTB^0xff; } }

Output:

Practical 2
Simulate Binary Counter at Port

Write a program in Assembly/C programming language to simulate binary counter on LEDs. Draw appropriate circuit diagram to demonstrate the above problem. Code:
#include <90s8535.h> #include <delay.h> //Global variable unsigned char led_status=0x01; void main(void) { DDRB=0xff; PORTB=led_status; //Unmasking the interrupt #asm("sei"); while (1) { PORTB=led_status; if(led_status==0x80) led_status=0x01; else led_status<<=1; delay_ms(1000); } }

Output:

Practical 3
Generate Delay Using TIMER_0

Write a program in Assembly/C programming language to configure the timer control register of microcontroller and generate the given timer delay. Draw appropriate circuit diagram to demonstrate the above problem. Code:
#include <90s8535.h> //Global variable int timecount=0; // Timer 0 overflow interrupt service routine interrupt [TIM0_OVF] void timer0_ovf_isr(void) { TCNT0=6; if(++timecount==1000) { PORTA=PORTA^0x01; timecount=0; } } void main(void) { // Input/Output Ports initialization // Port A initialization DDRA=0x01; PORTA=0x01; // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: 4000.000 kHz TCCR0=0x02; TCNT0=0; // Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x01; // Global enable interrupts #asm("sei") while (1); }

Output:

Practical 4
Stepper Motor (Clockwise / Anticlockwise)

Write a program in Assembly/C programming language for running a stepper motor in clockwise & anti-clockwise. Draw appropriate circuit diagram to demonstrate the above problem.

Code:
#include <90s8535.h> #include <delay.h> //Global variable unsigned char motor_status=0x01; void main(void) { DDRA=0x0f; DDRB=0x0f; #asm("sei") while(1) { PORTA=motor_status; PORTB=motor_status; delay_ms(2000); motor_status<<=1; if(motor_status==0x10) motor_status=0x01; } }

Output:

Practical 5 Generating square wave at port pin

Write a program in Assembly/C programming language for generating a square wave at a port pin. Draw appropriate circuit diagram to demonstrate the above problem. Code:
#include<90s8535.h> #include<delay.h> //Global variable unsigned int timecount=0; //Timer 0 overflow ISR interrupt [TIM0_OVF] void timer0_ovf_isr(void) { TCNT0=6;//reload for 500 microsec ticks if(++timecount==20) { PORTB=PORTB ^ 0x01;//toggle MSB of port B timecount=0;//clear for next 500 ms } } void main(void) { PORTB = 0x00; //Port B LSB as output DDRB=0x01; //set for clock=1MHz as counter's clock input TCCR0=0x01; //start timer with 0 in timer TCNT0=0x00; //Time 0 interrupt initialization //unmask Timer 0 overflow interrupt TIMSK=0x01; #asm ("sei") while(1){}; }

Output:
Circuit Diagram:

Oscillator:

Practical 6
Generating Triangular wave at port pin

Write a program in Assembly/C programming language for generating a triangular wave at a port pin. Draw appropriate circuit diagram to demonstrate the above problem. Code:
#include<90s8535.h> #include<delay.h> //Global variable int x; void main(void) { PORTA = 0x00; DDRA = 0xFF; while(1) { for (x = 0; x < 255; x++) { PORTA = x; } for (x = 254; x >= 0; x--) { PORTA = x; } } }

Output: Circuit Diagram:

Oscillator:

Practical 7
Sine wave generation using look-up table
Write a program in Assembly/C programming language for generating a sine wave using look-up table. Draw appropriate circuit diagram to demonstrate the above problem. Code:
#include <90s8535.h> #include<math.h> #include<delay.h> //Global variable unsigned int sine[] = {127,146,164,182,198,213,226,236,245,251,254,254,252,247,239,229,217,203,187,170,152,133,115,96, 78,61,46,33,21,12,5,1,0,1,5,12,21,33,46,61,78,96,115}; int i; void main() { PORTA = 0x00; DDRA = 0xFF; while(1) { for(i = 0;i<42;i++) { PORTA = sine[i]; } } }

Output: Circuit:

Oscillator:

Practical 8
Microcontrollers communicating over a serial link

Write a program in Assembly/C programming language that demonstrates the serial link communication. Draw appropriate circuit diagram to demonstrate the above problem. Code: Receiver:
#include <90s8535.h> #include <stdio.h> #include<delay.h> //Global variable unsigned char chin=0x00; unsigned char chout=0x00; interrupt [UART_RXC] void UART_receive_isr(void) { if(chout==0xff) chout=0x00; else chout++; } void main(void) { PORTA=0xff; DDRA=0xFF; #asm("sei") //Unmasking the interrupt UDR = chout; while (1) { chin = UDR; delay_ms(500); PORTA = chin; //UDR = chout; } }

Sender:
#include <90s8535.h> #include<delay.h> #include <stdio.h> //Global variable unsigned char chout=0x00; interrupt [UART_TXC] void UART_transmit_isr(void) { if(chout==0xff) chout=0x00; } void main(void) { // enable receiver, transmitter and transmit interrupt UCR=0x48; // baud rate = 9600 UBRR=0x33; //Unmasking the interrupt2/26/2007 #asm("sei") while (1) { delay_ms(500); UDR = chout++; } }

Output:

Practical 9
Read switch-status from i/p port and display at o/p port

Write a program in Assembly/C programming language that demonstrates the serial link communication. Draw appropriate circuit diagram to demonstrate the above problem. Write description of the above program and explain hardware and software part of above program. Draw o/p waveform if necessary. Code:
#include <90s8535.h> #include<stdio.h> #include<delay.h> void main(void) { int R1; PORTA=0x00; DDRA=0xFF; PORTD=0x00; DDRD=0xFF; DDRB=0x00; PORTB=0x00; while (1) { PORTD=0xFF; R1=PINB; delay_ms(1000); PORTA=R1; }; }

Output:

Practical 10
Using Input Capture Pin (ICP), Measure pulse width & display at o/p port

Write a program in Assembly/C programming language that measures the pulse width using the input-capture pin (ICP) and displays at the o/p port. Draw appropriate circuit diagram to demonstrate the above problem. Write description of the above program and explain hardware and software part of above program. Draw o/p waveform if necessary. Code:
#include <90s8535.h> #include <stdio.h> #define pulse_out PORTC #define ICP PIND.6 //Global variables unsigned char ov_counter; unsigned int rising_edge, falling_edge; unsigned long pulse_clock; //Interrupts interrupt[TIM1_OVF]void timer1_ovf_isr(void) { ov_counter++; } interrupt[TIM1_CAPT]void timer1_capt_isr(void) { if(ICP) { rising_edge=ICR1; TCCR1B=TCCR1B&0xBF; ov_counter=0; } else { falling_edge=ICR1; TCCR1B=TCCR1B|0x40; pulse_clock=(unsigned long)falling_edge-(unsigned long)rising_edge + (unsigned long)ov_counter *100000; pulse_out=pulse_clock/500; printf("value of puse is %d", pulse_out); } }

void main(void) { DDRC=0xFF; TCCR1B=0xC2; TIMSK=0x24; //Unmasking the interrupt #asm("sei") while (1){}; }

Output:
Circuit Diagram:

Signal generator:

Oscillator:

Practical 11
Working of Interrupt_0 on falling edge

Write a program in Assembly/C programming language that demonstrates the working of Interrupt_0 on the falling edge. Draw appropriate circuit diagram to demonstrate the above problem. Write description of the above program and explain hardware and software part of above program. Draw o/p waveform if necessary. Code:
#include <90s8535.h> // Interrupt interrupt [EXT_INT0] void ext_int0_isr(void) { PORTA=PORTA^0x01; } void main(void) { DDRB=0x01; PORTB=0x01; DDRA=0x01; GIMSK=0x40; MCUCR=0x02; //Unmasking the interrupt #asm("sei") while (1){}; }

Output:

Das könnte Ihnen auch gefallen