Saturday, November 9, 2019

Embedded Essays

Embedded Essays Embedded Essay Embedded Essay Paper II Section : II Embedded Systems INDEX No 1 2 3 4 5 6 7 8 9 10 Toggle Port LED Simulate Binary Counter at Port Generate delay using TIMER_0 Stepper Motor (clockwise/Anticlockwise) Generating square wave at port pin Generating Triangular wave at port pin Sine wave generation using look-up table Microcontrollers communicating over a serial link Read switch-status from i/p port and display at o/p port Using Input Capture Pin (ICP), measure pulse width display at o/p port Topic Date 6-9-2010 9-9-2010 17-9-2010 24-9-2010 8-10-2010 15-10-2010 15-10-2010 29-10-2010 22-11-2010 24-11-2010 Page 02 03 04 06 07 09 10 11 13 15 Sign Practical – 01 Toggle Port LED Aim : Write a program in embedded C programming language to alternately ON/OFF LEDs connected to 2 different ports. Components Used: i)AT90S8535 Micro controller ii)LED? S iii)Ground Code: #include #include void main(void) { DDRA = 0xff; PORTA = 0x00; DDRB = 0xff; PORTB = 0x00; while(1) { delay_ms(100); PORTA = 0x01; PORTB = 0x00; delay_ms(100); PORTA = 0x00; PORTB = 0x01; }; } Output: Mithibai College:-MSC COMPUTER SCIENCE PART II 3 Practical – 02 Simulate Binary Counter at Port Aim : Write a program using embedded C to simulate a binary counter. Components Used: i)AT90S8535 Micro controller ii)LED? S iii)Ground Code: #include #include void main() { DDRA = 0xff; PORTA=0x00; while(1) { delay_ms(100); if(PORTA == 0x80) PORTA = 0x01; else PORTA += 1; } } Description: First statement a unsigned char variable (unsigned integers are used to increase the range of numbers the variable can hold) is initialized to 0x01 . port A has been set to this variable . „+? perator stands for bit increment operation . we are incrimenting the bit of led_status to one position of binary number when the one at lsb reaches to the msb (0x80) of the variable we reinitialize the variable to 0x01. The Delay given is of one milli second so the bit shifts after every one second(1000ms) . Output: Mithibai College:-MSC COMPUTER SCIENCE PART II 4 Practical – 03 Generate delay using TIMER_0 Aim : Write a program using embedded C to generate delay using TIMER0. Components Used: i)AT90S8535 Micro controller ii)LED? S iii)Ground Code: #include int timeCount = 0; interrupt[TIM0_OVF] void timer0_ovf_isr(void) { TCNT0 = 6; if(++timeCount == 1000) { PORTA =PORTA ^ 0x01; timeCount = 0; } } void main(void) { DDRA = 0x01; PORTA = 0x01; TCCR0 = 0x02; TIMSK = 0x01; #asm(sei); while(1); } Description: A variable timecount is initialized to 0. In the main function the LSB of PORTA is chosen for output and it is set to 1. Then the TIMER COUNTER CONTROL REGISTER (TCCR0) is initialized in such a way that divide by 8 (CK/8)clock source is selected again the â€Å"timer interrupt mask is set to enable the timer0 counter. #asm† is a assembly language instruction „sei? stands for set enable interrupts to enable all the interrupts. Finaly ainfinite while loop. Then the function with keword interrupt is created. This function will be called automatically when the timer0 overflow interrupt takes place. This function returns nothing, since it is not called by any function and you cant pass any thing to f unction for the same reason . The timer0 is initialized to 6 in this function . As we have chosen ck/8 system as mentioned above and the clock frequency is 4 Mhz that? s why 4/8 Mhz so 500 Khz(0. Mhz) will be the effective frequency so for one tick of counter 1/0. 5 micro sec are required(1/freq. = time) that equals to 2 micro secondes. A timer can count 256 that? s why total of 256*2 that is 512 micro seconds are required . So to make it a round figure i. e. 500 microsecs we Mithibai College:-MSC COMPUTER SCIENCE PART II 5 have to omit 6 ticks of counters that is why we set timer (TCNT0 =6) to 6 so that it ticks from 6 to 256 hence ticks effectively for 250 times (250*2 = 500). and covers 500 micro secs ,when timecount is incremented up to 1000 (1000*500 micro secs = 0. secs). And led toggles after 0. 5 secs. Output: Mithibai College:-MSC COMPUTER SCIENCE PART II 6 Practical – 04 Stepper Motor (Clockwise/Anticlockwise) Aim : Write a program using embedded C to simulate Stepper Motor(Clockwise / AntiClockwise). Components Used: i)AT90S8535 Micro controlle r ii)LED? S iii)Ground iv)STEPPER MOTOR Code: #include #include unsigned char motorStatus = 0x01; void main(void) { DDRA = 0x0f; DDRB = 0x0f; #asm(sei); while(1) { PORTA = motorStatus; PORTB = motorStatus; delay_ms(200); motorStatus

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.