Sign in

username:

password:



Not a member?

Search m68hc11



Search tips

Subscribe to m68hc11



m68hc11 by Keywords

27c256 | 4K81H | 68HC11A1 | 68HC11P1 | 68hc24 | 68HC711E9 | 68HC811 | 8255 | A2D | ADC | ADC12138 | Am85C30 | BRCLR | Buffalo | CMOS | EEPROM | EPROM | Ethernet | EVB | EVBU | HC11E1 | HC11E9 | HC711E9 | Horray | ImageCraft | IRQ | Keypad | LCD | MC68HC11D0FN | MC68HC11E1CFU3 | MC68HC11F1 | MC68HC711E9 | MC68HC711E9CFN2 | Microcore11 | Microstamp11 | Minikit | NVRAM | PSD | PSD8xx | PSD9xx | PT1000 | RS232 | RTS | RXD | SPI | SRAM | TXD | Watchdogs | XIRQ

Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | | Software serial communication


Advertise Here

Software serial communication - Björn Gullander - Jun 25 10:53:00 2002

I need two serial communication ports from my 68hc11. Is it anyone who have tested to write a program for a serial port?
 





(You need to be a member of m68hc11 -- send a blank email to m68hc11-subscribe@yahoogroups.com )


RE: Software serial communication - Peter Mackel - Jun 25 11:05:00 2002

I've had to allow for two seperate Serial Ports from my HC11 and for them to work in parallel.  My first design I had to use Bit Banging, it's not pretty, but at 9600 baud it works fine.  You need to make sure however that you understand the HC11 timing very well.
 
My current design uses an external UART.  You can get plenty of them with 2 ports on them.  They are easy to configure and easy to use.  Perhaps that may be an option for you.
 
Regards
 
Peter
 

****************************************************
Peter Mackel
Design Engineer
Tel:    +44 2891 278528
Fax:    +44 2891 270156
Email:  p...@thermomax.co.uk
****************************************************

-----Original Message-----
From: Björn Gullander [mailto:b...@swipnet.se]
Sent: 25 June 2002 16:53
To: m...@yahoogroups.com
Subject: [m68HC11] Software serial communication

I need two serial communication ports from my 68hc11. Is it anyone who have tested to write a program for a serial port?
 

To unsubscribe from this group, send an email to:
m...@yahoogroups.com



Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.




(You need to be a member of m68hc11 -- send a blank email to m68hc11-subscribe@yahoogroups.com )

Re: Software serial communication - Author Unknown - Jun 25 12:38:00 2002

In a message dated 6/25/02 11:42:28 AM Eastern Daylight Time, b...@swipnet.se writes:

I need two serial communication ports from my 68hc11. Is it anyone who have tested to write a program for a serial port?


9600bps bitbanger for icc11v6 attached.....


//file bitbang.c
//send ascii out pa7 at 9600 bps
//June 25 2002 initial edit

//32k turbo microstamp:
//cpu: hc11ed0 9Mhz
//regs: 0x0000-0x003f
//512 bytes ram: 0x0040..0x01ff
//32k rom: 0x8000..0xffff
//stack: 0x01ff

#define _SCI
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "hc11ed0.h"

extern void _start(void); /* entry point in crt??.s */
extern char _bss_end;

//---ascii equates----------------
#define ESC 0x1b
#define CR 0x0d
#define LF 0x0a
#define CTLQ 0x11

//------vars in bss-------
//unsigned char istack[64];
unsigned char c,n;
unsigned char dispon;
unsigned char del;
unsigned char xirqflg;
unsigned char *pt;
unsigned char *pf;
unsigned char *p;
char teststring[80];

//---------------------
const char banner[]={"bitbang June 25 2002 q for cal menu\n"};

//---------------------
void _HC11Setup(void){
//init some hc11 regs

CONFIG=0x04; //nocop
DDRD=0x3a; //ss, sck, mosi, txd are outs, bit 5 disables modf
SPCR=0x50; //spi enab, mstr, cpha, 1mhz (1.25 with 9.8 mhz xtal)
TFLG2=0x40; //clr rti flg
PACTL |=0x80; //ddra7 output
}

//----------------------
void initsci(void){
//init sci to 38400
char jnk;

BAUD= 0x20; //0x20=38400 0x22=9600 baud 9MHz xtal (0x30=9600 8mhz xtal)
SCCR2=0x0c; //tx,rx enable
jnk=SCSR;
jnk=SCDR;
}

//-------------------------
void initvars(void){
//init vars

strcpy(teststring,"The quick brown fox jumped over the lazy dog's back.\n");
}

//----------------------
char kbhit(void){
//return nonzero if char in sci (polled version)

return(SCSR & RDRF);
}

//----------------------
int getchar(void){
//wait for char

while(!kbhit()){}; //wait
return SCDR;
}

//----------------------
void putc(char c){
//dont add lf after cr

while((SCSR & TDRE)==0){}; //wait
SCDR=c;
}

//----------------------
int putchar(char c) {
//adds lf after cr

if(c=='\n'){
putc('\r');
}
putc(c);
return c;
}

//----------------------
void putnibhex(unsigned char c){
//output bin nib c in hex

c+=0x30; //cvt to ascii
if(c > 0x39) c+=7; //handle a-f
putc(c);
}

//-----------------------
void putbytehex(unsigned char c){
//output c as 2 hex chars
unsigned char nib;

nib=(c & 0xf0) >>4;
putnibhex(nib);
nib=c & 0x0f;
putnibhex(nib);
}

//-----------------------
void putwordhex(unsigned int w){
//ouput w as 4 hex chars

putbytehex(w >> 8); //hi byte
putbytehex(w); //lo byte
}

//----------------------
void gotoxy(int x, int y){
//ansi cursor positioning sequence ESC[y;xH

putchar(ESC);
putchar('[');
printf("%d",y);
putchar(';');
printf("%d",x);
putchar('H');
}

//----------------------
void clrscr(void){
//clear ansi terminal screen

putc(ESC);
putc('[');
putc('2');
putc('J');
}

//------debug subs-----------
void dump256(unsigned char *n){
//dump 16 rows of 16 bytes
unsigned char r,c;
unsigned char *p, *pa, ch;

p=n;
printf("\n ");
for(c=0; c<16; c++){
printf("%02x ",c); //header
if(c==7) printf(" ");
}
printf("\n\n");
for(r=0; r<16; r++){
printf("%04x ",p); //print addr at beg of line
pa=p; //remember p for ascii
for(c=0; c<16; c++){
printf("%02x ",*p++); //print hex
if(c==7) printf(" ");
}
for(c=0; c<16; c++){
ch=*pa++;
if((ch > 0x20) && (ch !=0x0a) && (ch != 0x8a)) //if printing char
printf("%c",ch); //print ascii
else
printf(".");
if(c==7) printf(" ");
}
printf("\n");
}
}

//------------
unsigned char getche(void){
//get and echo a char
char c;

c=getchar();
putchar(c);
return(c);
}

//------------
unsigned char gethex(void){
//return a hex char
unsigned char b,c;

b=0xff; //error return value
c=toupper(getche());
if(isxdigit(c)) b=c-0x30; //if c ok, cvt ascii digit to binary
if((c>='A') && (c<='F')) b-=7; //if c hexcvt ascii A to binary 10
return(b);
}

//-------------
unsigned char getbyte(void){
//get 2 nibbles, return a binary byte
unsigned char n1,n2;

n1=gethex();
n2=gethex();
return((n1 << 4)+n2);
}

//-------------
unsigned int getaddr(void){
//return addr
unsigned int th,tl;

th=getbyte();
tl=getbyte();
return((th << 8)+tl);
}

//------------------
void examine(void){
//ask for mem range and dump
unsigned char *from;
unsigned char c;

printf("\nfrom:");
from=(unsigned char *)getaddr();
while(c!='q'){
dump256(from);
printf("np or q...");
c=getchar();
if(c=='n') from+=0x100;
if(c=='p') from-=0x100;
}
}

//------------------
void deposit(void){
//ask for addr and data
unsigned char *at;
unsigned char c;
unsigned char nh,nl;

printf("\nat:");
at=(unsigned char *)getaddr();
while(1){
printf(" %02x ",*at);
nh=gethex();
if(nh==0xff) return;
nl=gethex();
if(nl==0xff) return;
c=((nh << 4) | nl);
*at++=c;
}
}

//------------------
void fill(void){
//ask for mem range and fill char and fill
unsigned char *from, with;

printf("\nfrom:");
from=(unsigned char *)getaddr();
printf(" with:");
with=getbyte();
memset(from,with,256);
}

//------------------
void (* fn)(void); //fn prototype

void dojsr(void){
//ask for addr, jsr to it
unsigned char *to;

printf(" to:");
to=(unsigned char *)getaddr();
fn=(void *)to;
(*fn)(); //call function fn and returns
}
//----end of debug subs----------

//-------------------
void delnms(int n){
//delay n ms
char x;

while(n--){
x=73; //empirically determined fudge factor
while(x--);
}
}

//-------------------
void initxirq(void){
//enable xirq interrupt

asm("tpa"); //ccr to a
asm("anda #$bf"); //clear x bit in ccr
asm("tap"); //a to ccr
}

//------------------
void initscreen(void){

clrscr();
puts(banner);
}

//----------------------
void del104us(void){
//delay 1 bit time at 9600
char x;

x=6;
while(x--);
}

//-----------------------
void putaux(char c){
//bitbang c out pa7 at 9600bps 8,n,1,lsb first 104us/bit
//1.5 bits=152us
char b,msk;

INTR_OFF(); //just for 1ms...
msk=0x01;
PORTA &= ~0x80; //start bit lo
del104us(); //start bit bit time
// PORTA |=0x80; //start bit hi
for(b=0; b<8; b++){ //for 8 bits
if(c & msk){ // if bit is 1
PORTA &= ~0x80; //pa7 lo
}else{
PORTA |=0x80; //pa7 hi
}
msk <<=1;
del104us(); //rest of 1 bit time
}
PORTA |=0x80; //pa7 hi for stop bit
del104us(); //stop bit
INTR_ON();
}

//-----------------------
void printaux(char *p){
//print string at p out aux
char c;

while(1){
c=*p++;
if(c==0) break;
putaux(c);
}
}

//-----------------------
void dotest(void){
//print test string till q
char c;

printf("sending test string q to quit\n");
while(c !='q'){
if(kbhit()){
c=getchar();
}
printaux(teststring);
delnms(1);
}
}

//-----------------------
void dou(void){
//print UUUs till q
char c;

printf("sending UUUs q to quit\n");
while(c !='q'){
if(kbhit()){
c=getchar();
}
printaux("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUU");
delnms(1);
}
}

//--------------------------
void debugmenu(void){
//debug cmds

initscreen();
gotoxy(1,7);
printf("bitbang cmds:\n");
printf(" t test string\n");
printf(" u UUUs\n");
printf(" r restart\n");
printf("Debug cmds:\n");
printf(" e examine\n");
printf(" d deposit\n");
printf(" f fill\n");
printf(" j jsr\n");
}

//--------------------------
void debugswitch(char c){
//parse char from keyboard

switch(c){
case 't': dotest(); break;
case 'u': dou(); break;
case 'r': _start(); break;
case 'e': examine(); break;
case 'd': deposit(); break;
case 'f': fill(); break;
case 'j': dojsr(); break;
default: debugmenu();
}
}

//-----------------------
void rtloop(void){
//real time loop
char c;

printf("rtloop q to quit\n");
while(c != 'q'){
if(kbhit()){
c=getchar();
}
printaux(teststring);
delnms(1);
} //while
}

//-----------------
void main(void){
//main program
char c;

initsci();
initscreen();
initvars();
// _NewHeap(&_bss_end,&_bss_end+0x58); //create heap for malloc
// initxirq();
// rtloop();
while(1){ //main loop
debugmenu();
printf("\n>"); //prompt for input
c=getche();
debugswitch(c);
}
}

//------interrupt handlers-----------------------
#pragma interrupt_handler DUMMY_ENTRY
void DUMMY_ENTRY(void){
puts("unexpected interrupt!");
while(1){};
}

#pragma interrupt_handler xirqhdr
void xirqhdr(void){
//you have 10 ms 5v holdup to burn params in eeprom

// xirqflg++;
// if(xirqflg==1){
// powerfailrom();
// while((PORTA & 0x01)==0){ //pa0 lo?
// delnms(500);
// }
// asm("jmp __start"); //reloads stack pointer
// }else{
// printf("xirq %d!\n",xirqflg);
// }
puts("xirq!");
while(1){};
}

#pragma interrupt_handler scihdr
void scihdr(void){
//sci

puts("sci!");
while(1){};
}

#pragma interrupt_handler spihdr
void spihdr(void){
//spi

puts("spi!");
while(1){};
}

#pragma interrupt_handler irqhdr
void irqhdr(void){
//unvectored irq

puts("irq!");
while(1){};
}

#pragma interrupt_handler tofhdr
void tofhdr(void){
//tof

puts("tof!");
while(1){};
}

#pragma interrupt_handler swihdr
void swihdr(void){
//swi

puts("swi!");
while(1){};
}

#pragma interrupt_handler rtihdr
void rtihdr(void){
//count 65536 tics of 4.096ms

TFLG2=0x40; //clear interrupt flag
// tics++; //bump tics
// asm(" sts %tmpstk");
// if(tmpstk<minstk) minstk=tmpstk;
}

#pragma interrupt_handler illophndlr
void illophndlr(void){
//illegal opcode handler... dumps regs

puts("illop!");
while(1){};
// asm(" sts _pf"); //store stack pointer in a dedicated global variable
// asm(" lds #_istack+63");
// pf+=5; //get past 5 bytes on stack to see cc
// puts("\ncc b a x y pc sp");
// for(n=0; n < 9; n++){
// putbytehex(*pf++);
// putc(' ');
// }
// putwordhex((unsigned int)pf); //unrolled sp
// putchar('\n');
// c=getchar();
// asm("jmp __start"); //reloads stack pointer
}

#pragma interrupt_handler cophndlr
void cophndlr(void){
puts("cop!");
while(1){};
}

//-----reset vectors in end of rom--------------------
#pragma abs_address:0xffd6
void (*interrupt_vectors[])(void)={
scihdr, //SCI
spihdr, //SPI
DUMMY_ENTRY, //PAIE
DUMMY_ENTRY, //PAO
tofhdr, //TOF
DUMMY_ENTRY, //TOC5
DUMMY_ENTRY, //TOC4
DUMMY_ENTRY, //TOC3
DUMMY_ENTRY, //TOC2
DUMMY_ENTRY, //TOC1
DUMMY_ENTRY, //TIC3
DUMMY_ENTRY, //TIC2
DUMMY_ENTRY, //TIC1
rtihdr, //RTI
irqhdr, //IRQ
xirqhdr, //XIRQ
swihdr, //SWI
illophndlr, //ILLOP
cophndlr, //COP
DUMMY_ENTRY, //CLM
_start //RESET
};
#pragma end_abs_address
//--------eof-------------





(You need to be a member of m68hc11 -- send a blank email to m68hc11-subscribe@yahoogroups.com )