#include "mc8051fun/mc8051fun.h" #include "pinsh.h" void (*pinsh_output_chr)(char); uint8_t pinsh_buf[PINSH_BUF_SIZE]; volatile int pinsh_buf_pos=0; void pinsh_uart_irq_handler() { if (RI) { unsigned char b = SBUF; if (b=='\r'){ //pinsh_go=1; pinsh_exec(pinsh_buf); } else { SBUF=b; if (pinsh_buf_pos < PINSH_BUF_SIZE-1){ pinsh_buf[pinsh_buf_pos++]=b; pinsh_buf[pinsh_buf_pos]=0; } } RI=0; } } static void pinsh_output(const char *str) { while(*str) pinsh_output_chr(*str++); } void pinsh_welcome_msg() { pinsh_output("Pinsh 8051, V1.0\r\n"); } static void show_port(int n) { pinsh_output("P"); uint8_t b = getport(n); pinsh_output_chr(n+0x30); pinsh_output("="); for (int i=0; i<8; i++) { if (b&(1<<(7-i))) pinsh_output("1"); else pinsh_output("0"); } pinsh_output("\r\n"); } static void show_stat() { for (int i=0; i<4; i++) show_port(i); /* uint8_t b = P0; show_port("P0",b); b = P1; show_port("P1",b); b = P2; show_port("P2",b); b = P3; show_port("P3",b); */ } static void syntax_error() { pinsh_output("Syntax error\r\n"); } static void assign_pin(int n, int p, char val) { if (val){ switch(n){ case 0: P0 |= 1<0x33){ syntax_error(); return; } if(cmd[1]==0){ show_port(n-0x30); return; } if(cmd[1]=='='){ assign_port(n-0x30,cmd+2); return; } } void pinsh_exec(const char *cmd) { pinsh_output("\r\n"); if(cmd[0]=='p') pinsh_exec_p(cmd+1); pinsh_buf_pos=0; }