Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
MAX7456.cpp
00001 #include "mbed.h" 00002 #include "MAX7456.h" 00003 00004 namespace mbed { 00005 00006 00007 00008 MAX7456::MAX7456(PinName mosi, PinName miso, PinName clk, PinName ncs, PinName nrst, const char* name) 00009 : Stream(name), _spi(mosi, miso, clk), _ncs(ncs), _nrst(nrst) { 00010 00011 // initialisation code here 00012 00013 _nrst = 0; 00014 wait (0.5); 00015 _nrst = 1; 00016 wait (0.5); 00017 00018 // Setup the spi for 8 bit data, high steady state clock, 00019 // second edge capture 00020 _spi.format(8,0); 00021 00022 // 1MHz clock 00023 _spi.frequency(1000000); 00024 00025 } 00026 00027 00028 00029 00030 void MAX7456::cls() { 00031 int tmp=0; 00032 tmp = _read(DMM); 00033 tmp &= 0xFB; 00034 _write(DMM,tmp); //Make sure that DMM[2]=0 so that there can be write operations 00035 00036 tmp = _read(DMM); 00037 tmp |= 0x04; 00038 _write (DMM,tmp); //set DMM[2]=1 to clear all locations 00039 00040 // should wait until DMM[2] goes back to zero, so we know the reset it finished 00041 00042 } 00043 00044 00045 void MAX7456::locate(int x, int y) { //not sure if I understand the last line 00046 if ( (x<30) && (y<16) ) { 00047 int add = y*30+x; //formula for converting coordinates into denary location 00048 _write(DMAL,add); 00049 _write(DMAH,add>>8); // what does the ">>" mean? 00050 } 00051 } 00052 00053 00054 00055 int MAX7456::_getc() { 00056 return(0); 00057 } 00058 00059 00060 int MAX7456::_putc(int c) { 00061 00062 if ((c >= 0x31)&&(c <= 0x39)) { //characters from 1-9 00063 c= c-0x30; 00064 } else if ((c >= 0x41)&&(c <= 0x5A)) { // characters from A-Z 00065 c= c-0x36; 00066 } else if ((c >= 0x61)&&(c <= 0x7A)) { // characters from a-z 00067 c= c-0x3C; 00068 } else if ((c == 0x28)&&(c == 0x29)) { //brackets () 00069 c= c + 0x17; 00070 } 00071 00072 _write(DMDI,c); 00073 00074 return(c); 00075 } 00076 00077 00078 00079 00080 void MAX7456::vtrim(int v) { 00081 } 00082 00083 void MAX7456::htrim(int h) { 00084 } 00085 00086 00087 void MAX7456::format (char mode) { 00088 00089 if (mode == 'P') { 00090 write(VM0,0x78); // PAL 00091 } else if (mode == 'N') { 00092 write(VM0,0x78); // NTSC 00093 } 00094 00095 } 00096 00097 int MAX7456::_read(int address) { 00098 // force bit 7 to 1 for a read 00099 address |= 0x80; 00100 _ncs=0; // select device 00101 _spi.write(address); // send address 00102 int value = _spi.write(0x00); // send dummy 00103 _ncs=1; //deselect device 00104 return (value); 00105 } 00106 00107 void MAX7456::_write(int address, int data) { 00108 // force bit 7 to 0 for a write 00109 address &= 0x7f; 00110 // select the device 00111 _ncs = 0; 00112 // write VM1 00113 _spi.write(address); // send address 00114 _spi.write(data); // send some data 00115 // Deselect the device 00116 _ncs = 1; 00117 } 00118 00119 }
Generated on Sun Aug 21 2022 00:48:59 by
1.7.2