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.
Diff: MAX7456.cpp
- Revision:
- 0:869f2c6f960d
- Child:
- 1:ba08ad32bb88
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MAX7456.cpp Mon Aug 23 10:39:40 2010 +0000 @@ -0,0 +1,128 @@ +#include "mbed.h" +#include "MAX7456.h" + +namespace mbed { + + + +MAX7456::MAX7456(PinName mosi, PinName miso, PinName clk, PinName ncs, PinName nrst, const char* name) + : Stream(name), _spi(mosi, miso, clk), _ncs(ncs),_nrst(nrst) { + +// initialisation code here + + _nrst = 0; + wait (0.5); + _nrst = 1; + wait (0.5); + + // Setup the spi for 8 bit data, high steady state clock, + // second edge capture + _spi.format(8,0); + + // 1MHz clock + _spi.frequency(1000000); +} + + +void MAX7456::cls() { + int tmp=0; + tmp = _read(DMM); + tmp &= 0xFB; + _write(DMM,tmp); //Make sure that DMM[2]=0 so that there can be write operations + + tmp = _read(DMM); + tmp |= 0x04; + _write (DMM,tmp); //set DMM[2]=1 to clear all locations + + // should wait until DMM[2] goes back to zero, so we know the reset it finished + +} + + +void MAX7456::locate(int x, int y) { //not sure if I understand the last line + if ( (x<30) && (y<16) ) { + int add = y*30+x; //formula for converting coordinates into denary location + _write(DMAL,add); + _write(DMAH,add>>8); // what does the ">>" mean? + } +} + + + +int MAX7456::_getc() { + + return(0); +} + + +int MAX7456::_putc(int c) { + + if ((c >= 0x31)&&(c <= 0x39)) { //characters from 1-9 + c= c-0x30; + } else if ((c >= 0x41)&&(c <= 0x5A)) { // characters from A-Z + c= c-0x36; + } else if ((c >= 0x61)&&(c <= 0x7A)) { // characters from a-z + c= c-0x3C; + } else if ((c == 0x28)&&(c == 0x29)) { //brackets () + c= c + 0x17; + } + + _write(DMDI,c); + + return(c); +} + +void MAX7456::setdarkness(){ + _write(VM1,0xC7); + } + +void MAX7456::initaddress(){ + int d = _read(DMAH); + d= d&0xFC; + _write(DMAH,d); // setting DMAH[1]=0 + // to module to read/write character address byte + } + + + + +void MAX7456::vtrim(int v) { +} + +void MAX7456::htrim(int h) { +} + + +void MAX7456::format (char mode) { + + if (mode == 'P') { + _write(VM0,0x78); // PAL + } else if (mode == 'N') { + _write(VM0,0x78); // NTSC + } + +} + +int MAX7456::_read(int address) { +// force bit 7 to 1 for a read + address |= 0x80; + _ncs=0; // select device + _spi.write(address); // send address + int value = _spi.write(0x00); // send dummy + _ncs=1; //deselect device + return (value); +} + +void MAX7456::_write(int address, int data) { + // force bit 7 to 0 for a write + address &= 0x7f; + // select the device + _ncs = 0; + // write VM1 + _spi.write(address); // send address + _spi.write(data); // send some data + // Deselect the device + _ncs = 1; +} + +} \ No newline at end of file