/* * * doug_at.c * * usage: sdcc -mmcs51 doug_at.c * * Getting FLIP to work is troublesome. * * To put chip into boot mode, use this sequence. * * press reset, PSEN and release reset when PSEN pressed, then turn on USB switch. * rem rem compile doug_at.c and uses dfu-programmer to program the chip. rem https://sourceforge.net/projects/dfu-programmer/ rem sdcc -mmcs51 --std-c99 doug_at.c pause # use lsusb to see if in bootmode. lsusb # # You may need to use sudo otherwise you get device not present # sudo dfu-programmer at89c5131 get sudo dfu-programmer at89c5131 erase sudo dfu-programmer at89c5131 flash doug_at.ihx sudo dfu-programmer at89c5131 launch pause * http://www.futurlec.com/USBDevBoard.shtml * * The board will not go into bootmode with a 5V power supply plugged into jack * Use USB serial Lead to provide 5V * * at89_UART_doc4346.pdf * * remove rs232 chip * strap * . u . * . . * . . * . . * . . * . . * .---. * .---. * * . . . . * R G W B * 5v Tx Rx 0v * connect ttl serial lead to header : red, green, white, black * * * My PL2303HX TTL leads do not work with windows 10 but with LINUX * * https://github.com/dfu-programmer/dfu-programmer * */ #include #include void serial_IT(void) __interrupt 4 { char uart_data; if (RI == 1) { /* if reception occur */ RI = 0; /* clear reception flag for next reception */ uart_data = SBUF; /* Read receive data */ SBUF = uart_data; /* Send back same data on uart*/ } //else TI = 0; /* if emission occur */ } /* clear emission flag for next emission*/ static int intFlag; void int0_IT(void) __interrupt INT_EXT0 { intFlag = 1; } /* putchar is called by printf(); */ int putchar(int c) { while(!(SCON & 0x02)); SCON &= ~0x02; SBUF = c & 0xff; return (c); } void main(void) { unsigned long int i = 0; short x ; // ES = 1; /* Enable serial interrupt*/ // EA = 1; /* Enable global interrupt */ // Set up UART - Find the description in the User's manual! // Set up UART for 115200 baud - Find the description in the User's manual! // PCON|=128; // Baudrate double // SCON = 124; // 8 Bit UART - PC-compatible // TH1=250; // Divisor= -6 (57600/6=9600 Bd.) // TMOD=32; // use timer 1 as baudrate generator // TCON=64; // TR1 = 1; // TCON |= 0x40; // SCON |= 0x02; // Tell putchar() the UART is ready to send. /* ;************************************************* ; UART 115200bps ;************************************************* ORL CKCON0,#00000001B ; 6 CLK PERIOD/MACHINE ORL PCON,#11000000B ; ENABLE THE FRAMING BIT ERROR DETECTION, DOUBLE BAUD RATE ; AND CHECK FE BIT OF SCON SFR ORL BDRCON,#00001110B ; SPD=1,RBCK =1, TBCK =1 MOV SCON,#01010000B ; uart in mode 1 (8 bit), REN=1 MOV BRL,#243 ; U CAN SEE THIS VALUE FROM PAGE 71 OF DATASHEET ORL BDRCON,#00010000B ; BRR = 1 , START BAUD RATE RUN */ // this works. CKCON0 = 1; PCON = 0xC0; BDRCON = 0x0E; SCON = 0X50; BRL = 0xF3; // 243; BDRCON = BDRCON | 0x10; // TCON |= 0x40; SCON |= 0x02; // Tell putchar() the UART is ready to send. ES = 1; /* Enable serial interrupt*/ EA = 1; /* Enable global interrupt */ P0 = 0; x = 0x0 ; for(;;) { // set PORT 0 to count LED. PORT 0 is open drain. if ( intFlag == 1){ x++ ; intFlag = 0; } x++; P0 = x&0xff; printf("UUU 555 Hello World! x= %04X \n\r",x); // for(i = 0; i < 147456; i++); // Sleep for(i = 0; i < 14745; i++); // Sleep } }