Last active
November 28, 2016 08:43
-
-
Save moonblade/e1b729eba95aaa9440efa1c8ce104769 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 8051 serial communication | |
; ------------------------- | |
; Serial Controller, SCON register | |
; 7 SM0 9Fh Serial port mode bit 0 | |
; 6 SM1 9Eh Serial port mode bit 1. | |
; 5 SM2 9Dh Mutliprocessor Communications Enable (explained later) | |
; 4 REN 9Ch Receiver Enable. This bit must be set in order to receive characters. | |
; 3 TB8 9Bh Transmit bit 8. The 9th bit to transmit in mode 2 and 3. | |
; 2 RB8 9Ah Receive bit 8. The 9th bit received in mode 2 and 3. | |
; Ignore Everything Above, not needed | |
; 1 TI 99h Transmit Flag. Set when a byte has been completely transmitted. | |
; 99 is set, when mov a,sbuf Or a read operation is done | |
; 0 RI 98h Receive Flag. Set when a byte has been completely received. | |
; 98 is set when mov sbuf,a or a write operation is done | |
; Single byte sending | |
; Sender | |
; ------- | |
; Only A can move to sbuf, so add data to a | |
mov a,#56 | |
; Move the data to sbuf, serial buffer will automatically be available on the other side | |
mov sbuf,a | |
ending: sjmp ending | |
;Receiver | |
; -------- | |
; Data pit | |
mov dptr,#4500 | |
; clear receive flag, so that old data does not affect int | |
clr 98 | |
; wait till 98 is set, checks for a bit set | |
here : jnb 98,here | |
; Now data has come, read it and put it wherever | |
mov a,sbuf | |
; wherever | |
mov @dptr,a | |
ending: sjmp ending | |
; Array of size five Sending | |
; Sender | |
; ------- | |
; Data is gotten from here | |
mov dptr,#4600 | |
;no of data pts | |
mov r1,#05 | |
; clear transmit flag | |
repeat:clr 99 | |
; first time, we don't have to wait till read, so send directly | |
mov a,@dptr | |
mov sbuf,a | |
inc dptr | |
;next time, wait till he has read | |
here: jnb 99,here | |
;loop back | |
djnz r1,repeat | |
; Only A can move to sbuf, so add data to a | |
mov a,#56 | |
; Move the data to sbuf, serial buffer will automatically be available on the other side | |
mov sbuf,a | |
ending: sjmp ending | |
;Receiver | |
; -------- | |
; Data pit | |
mov dptr,#4500 | |
;no of data | |
mov r1,#05 | |
; clear receive flag, so that old data does not affect int | |
repeat:clr 98 | |
; wait till 98 is set, checks for a bit set | |
here : jnb 98,here | |
; Now data has come, read it and put it wherever | |
mov a,sbuf | |
; wherever | |
mov @dptr,a | |
inc dptr | |
djnz r1,repeat | |
ending: sjmp ending | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 13 | |
// 25 | |
// 12 | |
// 24 | |
// 11 | |
// 23 | |
// 10 | |
// 22 | |
// 09 D7 | |
// 21 | |
// 08 D6 | |
// 20 | |
// 07 D5 | |
// 19 | |
// 06 D4 | |
// 18 | |
// 05 D3 | |
// 17 | |
// 04 D2 | |
// 16 | |
// 03 D1 | |
// 15 | |
// 02 D0 | |
// 14 | |
// 01 | |
// This will be the view after the cable has been connected | |
// We need the pins D0 to D7 | |
// Connect those to led for output mode test | |
// Connect to switch for input mode test | |
// Connect to D0 to D7 of second computer for communication | |
// Programs | |
// -------- | |
// Sender/Output | |
// ------------- | |
/*For shit requiring io port manipulations*/ | |
#include<sys/io.h> | |
/*Address of parallel port, 0x is hex, 378 is hex address*/ | |
portAddress=0x378 | |
/*get permission for 3 bytes after 378, (ie, addresses 0x378, 0x379, 0x37A*/ | |
/*base - which address to start asking for permission*/ | |
/*3 - how many bytes required*/ | |
/*1 - permission bool, 1 - get perm, 0 - release perm*/ | |
/*Returns 0 if success and -1 if fail*/ | |
returnVal=ioperm(base,3,1); | |
if (returnVal==-1) | |
// failed | |
/*Set 0x37A, the command register to make parallel port act in output mode*/ | |
outb(0x0B,base+2); | |
/*output number you want, maybe in loop, maybe from file, wherever*/ | |
// loop maybe? | |
outb(mynumber,base); | |
/*Release perm*/ | |
ioperm(base,3,0); | |
// Input/Receiver | |
// -------------- | |
/*For shit requiring io port manipulations*/ | |
#include<sys/io.h> | |
/*Address of parallel port, 0x is hex, 378 is hex address*/ | |
portAddress=0x378 | |
/*get permission for 3 bytes after 378, (ie, addresses 0x378, 0x379, 0x37A*/ | |
/*base - which address to start asking for permission*/ | |
/*3 - how many bytes required*/ | |
/*1 - permission bool, 1 - get perm, 0 - release perm*/ | |
/*Returns 0 if success and -1 if fail*/ | |
returnVal=ioperm(base,3,1); | |
if (returnVal==-1) | |
// failed | |
/*Set 0x37A, the command register to make parallel port act in input mode*/ | |
// DIFFERENCE | |
outb(0x2B,base+2); | |
/*input from base, maybe in loop to a file? wherever*/ | |
// loop maybe? | |
// DIFFERENCE | |
mynumberReceived=inb(base); | |
/*Release perm*/ | |
ioperm(base,3,0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment