Lecture Notes on sr-Broken, c - Microprocessor System Design | ECE 473, Study notes of Microprocessors

Material Type: Notes; Professor: Traylor; Class: MICROPROCESSOR SYSTEM DESIGN; Subject: Electrical & Computer Engineer; University: Oregon State University; Term: Fall 2006;

Typology: Study notes

Pre 2010

Uploaded on 08/30/2009

koofers-user-ab9-1
koofers-user-ab9-1 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1

Partial preview of the text

Download Lecture Notes on sr-Broken, c - Microprocessor System Design | ECE 473 and more Study notes Microprocessors in PDF only on Docsity!

cre 06 T7184 7/_s¢_broken.¢ /PRLT 10.6.06 //Phis code serially shifts out a pattern to a 74HC595 ¢/that causes the LEDs attached to its outputs to light //one at a time in an ascending pattern from bit 0 to //bit 7, Ie illuminates each LED for about 1/2 sec. include « uint8_t out_var; //global for holding output data //simply creates a good sized delay void pause (}{ wint32_t i; for({i=0; 1<=100000; i++) {} 3 //twiddle the shift register clock pin te shift in data void clk_shift_reg(){ /f/toggle bit 1 -~ shift register clock PORTB = 0x02; PORTB = OxFD; } /ftwiddle the output register clock pin to output data void clk_output_reg()( //toggle bit 2 -- output register clock PORTR PORTB 3 //sends out the eight bits of data stored in ovt_var //uses a moving mask to detect the value each bit void send_data(){ //send eight bits of data wints_t mask; uints_e i; mask = 0x01; //setup bit mask for(i=0; i<=8; i++) { //d0 for 8 bits elk_shift_reg(); //elock data bit 4£(out_var & mask) ¢étest each bit of out_var PORTB = PORTB | 0x01; //set data bit to 1 else PORTB = PORTS & OxFE; //set data bit to 0 mask = mask << 1; //shift mask left once wu g 4 2 d//for }//send_data Z/main int main(} { uint8_t i.4; DDRB = 0x07; //lower three bits of port B form interface //0=data, I=shiftreg clock, 2=output reg clk PORTB = 0x00; /tinitalize to zero while (1) { /ido forever out_var = 0x01; //start with bit in zero position fox (is0; i<=7) i++) ( ¢érotate through all bit positions send_data{); //send 8 bits elk_output_reg(); //send data to output register out var = out_var << 1; //shift the bit left for next time for(j=0; j<=20; j++) pause); /éwait 0.5 sec to make it visible V//tor i /twhile V/fnain Friday October 06, 2006 st_broken.c Printed by Traylor Roger com Jes tomage, 4 rag bho = | pete) | Port .2 (Keam/odnte) Ls Poet Colve) sift negisha, 4A