#include/* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */
#define SDA PTT_PTT1 //Data port 1
#define SCL PTT_PTT0 // Clock
#define DC PTT_PTT3
#define RST PTT_PTT2
/******************************/
/*void delay(uint a){
uint b;
for(a;a>0;a--)
for(b=1000;b>0;b--);
} */
void InitAD(void) {
ATD0DIEN=0X00;
ATD0CTL1=0X20;
ATD0CTL2=0X40;
ATD0CTL3=0X8C;
ATD0CTL4=0X03;
ATD0CTL5=0X20;
}
/********************************/
const uint m[]={ 8829,8494,8166,7852,7552,7266,6992,6731,6481,6242,
6013,5782,5581,5379,5185,5000,4821,4650,4487,4329,
4170,4033,3894,3760,3631,3508,3390,3276,3167,3062,
2962,2864,2770,2680,2593,2510,2429,2352,2278,2206,
2138,2070,2006,1944,1884,1826,1771,1717,1665,1616,
1568,1521,1476,1433,1391,1351,1312,1274,1238,1200,
1169,1136,1104,1073,1043,1014,986,959,933,908};
const byte tab_num[][16]= //Digital font
{
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},/*"0",0*/
{0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"1",1*/
{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},/*"2",2*/
{0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00},/*"3",3*/
{0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00},/*"4",4*/
{0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00},/*"5",5*/
{0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00},/*"6",6*/
{0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00},/*"7",7*/
{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},/*"8",8*/
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00},/*"9",9*/
};
/*************************************/
void wrdata(byte data){
byte i=8;
DC=1;
SCL=0;
while(i--){
if(data&0x80)
SDA=1;
else
SDA=0;
SCL=1;
_asm(nop);
SCL=0;
data<<=1;
}
}
void wrcmd(byte cmd){
byte i=8;
DC=0;
SCL=0;
while(i--){
if(cmd&0x80)
SDA=1;
else
SDA=0;
SCL=1;
_asm(nop);
SCL=0;
cmd<<=1;
}
}
void set_xy(byte x,byte y){
wrcmd((y|0xb0));
wrcmd((x&0x0f));
wrcmd(((x&0xf0)>>4)|0x10);
}
void clear_oled(void)
{
byte page,x;
set_xy(0,0);
for(page=0;page<9;page++)
{
for(x=0;x<128;x++){wrdata(0x00);}
set_xy(0,page);
}
}
void init_oled(void){
DDRT=0XFF;
SCL=1;
RST=0;
_asm(nop);
_asm(nop);
RST=1;
wrcmd(0xae);
wrcmd(0xD5);
wrcmd(0x80);
wrcmd(0xA8);
wrcmd(0x3f);
wrcmd(0xd3);
wrcmd(0x00);
wrcmd(0x40);
wrcmd(0x8d);
wrcmd(0x14);
wrcmd(0x20);
wrcmd(0x02);
wrcmd(0xa1);
wrcmd(0xc8);
wrcmd(0xea);
wrcmd(0x12);
wrcmd(0x81);
wrcmd(0xef);
wrcmd(0xd9);
wrcmd(0xf1);
wrcmd(0xdb);
wrcmd(0x30);
wrcmd(0xa4);
wrcmd(0xa6);
wrcmd(0xaf);
clear_oled();
}
void display_num(byte x,byte y,byte w) {
byte c;
set_xy(x,y);
for(c=0;c<8;c++) { wrdata(tab_num[w][c]); }
set_xy(x,y+1);
for(c=8;c<16;c++) { wrdata(tab_num[w][c]); }
}
void main(void){
unsigned char v;
uint t,t1,t2,t3,t4,t5,x,t7,t8,t9,t10,t11;
head t6;
DDRT=0XFF;
DDRB=0XFF;
DDRP=0XFF;
InitAD();
init_oled();
for(;;) {
PTP_PTP3=0;
while(!ATD0STAT2L_CCF0){
;}
v=ATD0DR0L;
t=(int)v;
t6=t*100000/(1023-t);
for(x=0;x<70;x++){
if(t6>m[x+1]&&t6
t3=x; break;
}
}
t1=t/100;
t2=(t%100)/10;
t11=t%10;
t4=t6/1000;
t5=(t6%1000)/100;
t7=(t6%100)/10;
t8=t6%10;
t9=(t3/10)+1;
t10=t3%10;
display_num(16,0,t1);
display_num(24,0,t2);
display_num(32,0,t11);
display_num(16,3,t4);
display_num(24,3,t5);
display_num(32,3,t7);
display_num(40,3,t8);
display_num(16,5,t9);
display_num(24,5,t10);
_FEED_COP();
}
}
Previous article:Bootloader for S12(X) microcontrollers
Next article:Output the voltage value of different AD buttons through AD sampling
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Boa application - web page configuration A40i development board - Feiling domestic industrial-grade Allwinner A40i series dry goods sharing
- [Recruitment] Part-time electronic hardware engineer located in Pudong, Shanghai
- How to select a display detector
- Basic Working Principle of Brushless DC Motor
- Ant basic antenna array comes with PPT
- 【AT-START-F425 Review】+ ERTC and the implementation of electronic clock
- How to use FPGA coprocessor to realize algorithm acceleration
- 【Gravity:AS7341 Review】+Garbage Sorting Video
- Construction of CCS v5 software development environment for TMS320C6000
- Is there anyone who uses relays to perform temperature control PID adjustment? How do you determine the PID parameters?