📄 testmode.c
字号:
/* ---------------------------------------------------------------------------- * testmode.c * functions that switch the state of the signal lines for test the * wiring to the microcontroller. * * Copyright 2003/2004 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * ----------------------------------------------------------------------------*/#ifdef HAVE_CONFIG_H# include <config.h>#endif#include <stdio.h>#include <unistd.h>#include <ctype.h>#include "isp-at89.h"voidtestmode (char *device){ char mykey; char myloop = 1; unsigned char mydata = 0; unsigned char myread = 0; int fd; if ((fd = parport_gethandle(device)) != ERROR) { printf (_("\nTestmode:\n")); printf (_("=========\n\n")); printf (_("Connect PC and chip as follows:\n\n")); printf (_("Printer Port ATMEL 89S8252\n")); printf ("Pin:6 (D4) <----> Pin:9 (RESET)\n"); printf ("Pin:7 (D5) <----> Pin:6 (MOSI)\n"); printf ("Pin:8 (D6) <----> Pin:8 (SCK)\n"); printf ("Pin:10 (ACK) <----> Pin:7 (MISO)\n"); printf ("Pin:25 (GND) <----> Pin:20 (GND)\n\n"); printf (_("Press a key for toggling the state of the pin\n")); printf (_("or press <q> for exit the testmode.\n\n"));#ifdef DEBUG printf(" DBG: Value of variable fd: %i\n", fd);#endif while (myloop) { myread = parport_wdata (fd, mydata); /* Dump the state from the port */ if (mydata & RESET) printf ("<R>ESET = 5V "); else printf ("<r>eset = 0V "); if (mydata & MOSI) printf ("M<O>SI = 5V "); else printf ("m<o>si = 0V "); if (mydata & SCK) printf ("<S>CK = 5V "); else printf ("<s>ck = 0V "); if (myread) printf ("M<I>SO = 5V\r"); else printf ("m<i>so = 0V\r"); /* Wait for a key */ mykey = getchar(); printf ("\r"); switch (tolower(mykey)) { case 'r': mydata = mydata & RESET ? mydata & ~RESET : mydata | RESET; break; case 'o': mydata = mydata & MOSI ? mydata & ~MOSI : mydata | MOSI; break; case 's': mydata = mydata & SCK ? mydata & ~SCK : mydata | SCK; break; case 'q': case 'x': printf (" \n"); myloop=0; break; } } printf ("\n"); parport_release(fd); /* clean up interface */ close(fd); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -