| WEL COME ON register and get guru's mail |
| | Microcontroller INTERFACING programs | |
| | Author | Message |
---|
Admin Admin
Posts : 185 Join date : 2007-07-30
| Subject: Microcontroller INTERFACING programs Tue Jul 31, 2007 7:30 pm | |
| Here some of the interfacing programs are given. Devices like 7-segment display, stepper motor, ADC, DAC, Keyboard are interfaced to 8951 microcontroller. Also wave generator, serial communication and interrupt programs are given. PROGRAM TO INTERFACE 7-SEGMENT DISPLAY. PROGRAM TO ROTATE STEPPER MOTOR USING 8255 PORTS. PROGRAM TO INTERFACE ADC PROGRAM TO GENERATE STAIRCASE WAVE USING DAC PROGRAM TO GENERATE TRIANGLE WAVE USING DAC PROGRAM TO GENERATE SINE WAVE OF 200Hz USING DAC. PROGRAM TO FIND THE FREQUENCY OF A SQUARE WAVE PROGRAM FOR SERIAL COMMUNICATION TO GENERATE RECTANGLE WAVE OF 500 Hz WITH 60% DUTY CYCLE USING TIMER 1 MODE 1 TO GENERATE SQUARE WAVE OF 500 Hz USING TIMER 1 MODE 1 TO GENERATE SQUARE WAVE OF 10K Hz USING TIMER 1 MODE 2 PROGRAM TO INTERFACE KEYBOARD USING 8255 PORTS. PROGRAM TO GENERATE REAL TIME CLOCK USING TIMER AND INTERRUPT. PROGRAM TO INTERFACE 7-SEGMENT DISPLAY Here 7-segment is connected to Port 1 of 8051 microcontroller. Here look up table is stored from the memory location 19H. To display any number first get the 7-segment equivalent code and then send to port 1. mov r0,#19h mov @r0,#0bfh inc r0 mov @r0,#86h inc r0 mov @r0,#0dbh inc r0 mov @r0,#0cfh inc r0 mov @r0,#0e6h inc r0 mov @r0,#0edh inc r0 mov @r0,#fdh inc r0 mov @r0,#87h inc r0 mov @r0,#0ffh inc r0 mov @r0,#0e7h again: mov a,#00h up: mov r2,a mov r0,#19h add a,r0 mov r0,a mov a,@r0 mov p1,a mov r3,#255 here1: mov r1,#255 here: djnz r1,here djnz r3,here1 mov a,r2 inc a cjne a,#0ah,up sjmp again | |
| | | Admin Admin
Posts : 185 Join date : 2007-07-30
| Subject: PROGRAM TO ROTATE STEPPER MOTOR USING 8255 PORTS Tue Jul 31, 2007 7:40 pm | |
| PROGRAM TO ROTATE STEPPER MOTOR USING 8255 PORTS A stepper motor is a widely used device that translates electrical pulses into mechanical movement. The most common stepper motors have four coils. The stepper motor discussed here has 6 leads: 4 leads representing the four stator windings and 2 commons for the center tapped leads. As the sequence of power is applied to each stator winding, the rotor will rotate. One way to rotate stepper motor is energizing a coil at a time. So you have to transmit the sequence as shown bellow . Step Winding A Winding B Winding C Winding C 1 1 0 0 0 2 0 1 0 0 3 0 0 1 0 4 0 0 0 1 mov a,#11h ;move 11 to acc h3: mov p1,a ;send (acc) to port A rr a ;rotate (acc) to right mov r2,#50 ;delay h1: mov r1,#255 h2: djnz r1,h2 djnz r2,h1 jmp h3 .end | |
| | | Admin Admin
Posts : 185 Join date : 2007-07-30
| Subject: PROGRAM TO INTERFACE ADC Tue Jul 31, 2007 7:41 pm | |
| PROGRAM TO INTERFACE ADC Here ADC 0804 is connected to port1 of 8051.WR and INTR of ADC is connected to P3.4 and P3.5 respectively. Analog input is applied to pin 6 of ADC. Here WR is the start of conversion and INTR is the end of conversion. In this program if input voltage accedes certain range then 8255 sets corresponding bits mov a,#80h mov dptr,#2023h movx @dptr,a mov p1,#ffh ; configuring port 1 as i/p start: clr p3.4 ; low to high signal to WR, start of conversion setb p3.4 here3: jb p3.5,here3 ; check whether conversion is over, pin-INTR mov a,p1 mov r5,a mov r6,a lcall 66d3h mov dptr,#2020h mov a,r5 subb a,#cch ; check whether i/p is greater than 4V jc L4v ; jump if input is less than 4V mov a,#10h ; send high signal to 5th line movx @dptr,a jmp last L4v: mov a,r5 subb a,#99h ; check whether i/p is greater than 3V jc L3v ; jump if input is less than 3V mov a,#08h ; send high signal to 4th line movx @dptr,a jmp last L3v: mov a,r5 subb a,#66h ; check whether i/p is greater than 2V jc L2v ; jump if input is less than 2V mov a,#04h ; send high signal to 3rd line movx @dptr,a jmp last L2v: mov a,r5 subb a,#33h ; check whether i/p is greater than 1V jc L1v ; jump if input is less than 1V mov a,#02h ; send high signal to 2nd line movx @dptr,a jmp last L1v: mov a,r5 mov a,#01h ; send high signal to 1st line movx @dptr,a last: mov r1,#0ffh here: djnz r1,here mov r2,#0ffh here1: djnz r2,here1 jmp start .end | |
| | | Admin Admin
Posts : 185 Join date : 2007-07-30
| Subject: PROGRAM TO GENERATE STAIRCASE WAVE USING DAC Tue Jul 31, 2007 7:43 pm | |
| PROGRAM TO GENERATE STAIRCASE WAVE USING DAC Here DAC 0808 is connected to port 1 of 8051. To check Staircase wave you can connect output to CRO. start: mov a,#00 ;move zero to accumulator loop: mov p1,a ;move (accumulator) to port 1 add a,#33h ;add 33 to accumulator mov r1,#0ffh ;delay PROGRAM TO GENERATE TRIANGLE WAVE USING DAC mov a,#0 ;move zero to accumulator up: mov p1,a ;move (accumulator) to port 1 inc a ;increment the (accumulator) cjne a,#0ffh,up ;compare (accumulator) with ff down: dec a ;decrement the (accumulator) mov p1,a ;move (accumulator) to port 1 cjne a,#00,down ;compare (accumulator) with 0 sjmp up ;repeat again PROGRAM TO GENERATE SINE WAVE OF 200Hz USING DAC mov r0,#08 ;look up table is stored in internal RAM mov @r0,#7eh inc r0 mov @r0,#9fh inc r0 mov @r0,#0bfh inc r0 mov @r0,#0d9h inc r0 mov @r0,#0feh inc r0 mov @r0,#0fah inc r0 mov @r0,#0ffh inc r0 mov @r0,#0fah inc r0 mov @r0,#0eeh inc r0 mov @r0,#0d9h inc r0 mov @r0,#0bfh inc r0 mov @r0,#9fh inc r0 mov @r0,#7eh inc r0 mov @r0,#5eh inc r0 mov @r0,#3fh inc r0 mov @r0,#25h inc r0 mov @r0,#11h inc r0 mov @r0,#4 inc r0 mov @r0,#0 inc r0 mov @r0,#4 inc r0 mov @r0,#11h inc r0 mov @r0,#25h inc r0 mov @r0,#3fh inc r0 mov @r0,#5eh start: mov r1,#18h ;load count in r1 mov r0,#08 ;load starting address of look up table to r0 up: mov a,@r0 ;get the data from look up table mov p1,a ;send data to port 1 inc r0 ;increment the look up table address mov r3,#92 ;delay to get 200Hz frequency loop: djnz r3,loop djnz r1,up sjmp start delay: djnz r1,delay cjne a,#32h,loop ;compare (acc) with 32 jmp start | |
| | | Admin Admin
Posts : 185 Join date : 2007-07-30
| Subject: PROGRAM TO FIND THE FREQUENCY OF A SQUARE WAVE Tue Jul 31, 2007 7:44 pm | |
| PROGRAM TO FIND THE FREQUENCY OF A SQUARE WAVE Here unknown square wave is applied to P3.4. To get the frequency you have to count the number of pulses in a second. Next display that count using 7-segment display. org 9000h begin: mov tcon,#00h mov r0,#0d6h ;lsb of delay mov r1,#22h ;msb of delay mov tmod,#25h ;t1-mode2 timer,t0-mode1 counter mov th1,#0a2h ;delay of .1ms mov th0,#00h mov tl0,#00h ;initialize counter clr a.5 mov ie,#88h ;enable t1 overflow interrupt mov tcon,#50h ;initiate counting up: jb a.5,dsply sjmp up dsply: mov p1,tl0 mov p2,th0 lcall 66c1h ;display frequency sjmp begin Interrupt service routine org 8028h djnz r0,skip ;check whether 1sec is over by djnz r1,skip ;decrementing R0 & R1 clr tr0 ;stop counter clr tr1 ;stop timer setb a.5 skip: reti .end | |
| | | Admin Admin
Posts : 185 Join date : 2007-07-30
| Subject: PROGRAM FOR SERIAL COMMUNICATION Tue Jul 31, 2007 7:45 pm | |
| PROGRAM FOR SERIAL COMMUNICATION The 8051 has two pins that are used specifically for transferring and receiving data serially. These two pins are called TxD and RxD are the part of port 3. | |
| | | Admin Admin
Posts : 185 Join date : 2007-07-30
| Subject: Re: Microcontroller INTERFACING programs Tue Jul 31, 2007 7:45 pm | |
| TRANSMITTER PROGRAM
mov tmod,#20h ;Timer 1 mode 2
mov th1,#fdh ;9600 baud rate
mov r0,#20h
mov scon,#50h ;8-bit, 1 stop bit, REN enabled
mov r1,#05h ;5 data to transmit
clr ti ;Ready for transmitting
movx a,@r0
mov sbuf,a ;move transmitting data to sbuf
setb tr1 ;Start timer 1
here: jnb ti,here ;wait for last bit to transfer
clr ti ;get ready for next byte
inc r0
movx a,@r0
mov sbuf,a ;load the next data
djnz r1,here
lcall 03h
.end
RECEIVER PROGRAM BY POLLING METHOD
mov tmod,#20h ;Timer 1, mode 2
mov th1,#fdh ;9600 baud rate
mov r0,#20h
mov scon,#50h ;8-bit, 1 stop bit, REN enabled
clr ri ;Ready to receive
setb tr1 ;start timer
here: jnb ri,here ;wait for last bit to receive
mov a,sbuf ;move received data to a
movx @r0,a
clr ri ;get ready for next byte
inc r0
sjmp here
.end
RECEIVER PROGRAM BY INTERRUPT METHOD
mov ie,#90h
mov tmod,#20h ;Timer 1, mode 2
mov th1,#fdh ;9600 baud rate
mov dptr,#9000h
mov scon,#50h ;8-bit, 1 stop bit, REN enabled
clr ri ;ready to receive
setb tr1 ;start timer
here: sjmp here
Interrupt service routine.
mov a,sbuf ;move received data to a
movx @dptr,a
clr ri ;get ready for next byte
inc dptr
reti
TO GENERATE RECTANGLE WAVE OF 500 Hz WITH 60% DUTY CYCLE USING TIMER 1 MODE 1
mov tmod,#10h ;timer 1, mode 1
start: mov th1,#fbh ;load count - ON time
mov tl1,#aah
setb p1.0 ;set output
setb tr1 ;start timer
back: jnb tf1,back ;check overflow flag
clr tf1
clr p1.0 ;clear output
mov th1,#fdh ;load count - OFF time
mov tl1,#1eh
setb tr1 ;start timer
back1: jnb tf1,back1 ;check overflow flag
clr tf1
sjmp start
TO GENERATE SQUARE WAVE OF 500 Hz USING TIMER 1 MODE 1
mov tmod,#10h ;timer 1, mode 1
start: mov th1,#0fch ;load the count to t1
mov tl1,#68h
cpl p1.0 ;compliment output
setb tr1 ;start timer
back: jnb tf1,back ;check timer 1 overflow flag
clr tf1
sjmp start
TO GENERATE SQUARE WAVE OF 10K Hz USING TIMER 1 MODE 2
mov tmod,#20h ;timer 1,mode 2 mov th1,#210 ;load the count
setb tr1 ;start timer
back: jnb tf1,back ;check timer 1 overflow flag
cpl p1.0 ;compliment output
clr tf1
sjmp back | |
| | | Admin Admin
Posts : 185 Join date : 2007-07-30
| Subject: PROGRAM TO INTERFACE KEYBOARD USING 8255 PORTS Tue Jul 31, 2007 7:47 pm | |
| PROGRAM TO INTERFACE KEYBOARD USING 8255 PORTS Here 8255 is interfaced to 8051 and that 8255 ports are used for keyboard interfacing. You can directly use 8051 ports. Here Port A is configured as input port and Port C is configured as output port. mov a,#90h mov dptr,#2023h ;configure 8255 ports movx @dptr,a ;port A-i/p, port C-o/p start: mov a,#07h mov dptr,#2022h movx @dptr,a ;set all rows HIGH mov dptr,#2020h wait: movx a,@dptr jz wait ;wait until a key is pressed mov r1,#00h ;number of key mov a,#01h ;to set 1 row HIGH nextrow: mov dptr,#2022h mov r2,a movx @dptr,a mov dptr,#2020h movx a,@dptr jnz colscan ;scan cols. if any key is pressed in that row mov a,r1 add a,#03h mov r1,a ;inc key no. by 8 mov a,r2 rl a ajmp nextrow colscan: rrc a ;get the pressed number jc done inc r1 ajmp colscan done: mov r6,r1 ;display the pressed number lcall 66d3h mov dptr,#2020h loop: movx a,@dptr ;stay here until key is released jnz loop ajmp start .end PROGRAM TO GENERATE REAL TIME CLOCK USING TIMER AND INTERRUPT org 9000h mov tmod,#20h ;configuring timer t1,mode 2 mov th1,#01h ;load count 553us of delay mov ie,#88h ;enable timer1 overflow interrupt lcall 66f5h ;Input the hours and minutes from the keyboard mov r6,31h ;minutes mov r4,32h ;hours mov r5,#00 ;seconds setb tr1 ;start timer back2: jmp back2 org 8028h ;timer interrupt routine mov r0,#212 lcall 6798h ;Delay of 999.45ms inc r5 ;increment second mov a,r5 add a,#00 da a ;Decimal adjustment mov r5,a xrl a,#60h ;compare second is equal to 60 jz min jmp last min: mov r5,#00h inc r6 ;increment minute mov a,r6 add a,#00 da a ;Decimal adjustment mov r6,a xrl a,#60h ;compare minute is equal to 60 jz hr jmp last hr: mov r6,#00h inc r4 ;increment hour mov a,r4 add a,#00 da a ;Decimal adjustment mov r4,a xrl a,#24h ;compare hour is equal to 24 jnz last mov r4,#00 last: push r5 ;Display the Time push r6 push r4 mov r7,r4 lcall 66c1h ;Address field mov r6,r5 lcall 66d3h ;Data field pop r4 pop r6 pop r5 clr tf1 reti | |
| | | Sponsored content
| Subject: Re: Microcontroller INTERFACING programs | |
| |
| | | | Microcontroller INTERFACING programs | |
|
Similar topics | |
|
| Permissions in this forum: | You cannot reply to topics in this forum
| |
| |
| |
|